Ejemplo n.º 1
0
def test_press_move_release(gslider: QRangeSlider, qtbot):
    assert gslider._pressedControl == QStyle.SubControl.SC_None

    opt = QStyleOptionSlider()
    gslider.initStyleOption(opt)
    style = gslider.style()
    hrect = style.subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle)
    handle_pos = gslider.mapToGlobal(hrect.center())

    with qtbot.waitSignal(gslider.sliderPressed):
        qtbot.mousePress(gslider, Qt.LeftButton, pos=handle_pos)

    assert gslider._pressedControl == QStyle.SubControl.SC_SliderHandle

    with qtbot.waitSignals([gslider.sliderMoved, gslider.valueChanged]):
        shift = QPoint(
            0, -8) if gslider.orientation() == Qt.Vertical else QPoint(8, 0)
        gslider.mouseMoveEvent(_mouse_event(handle_pos + shift))

    with qtbot.waitSignal(gslider.sliderReleased):
        qtbot.mouseRelease(gslider, Qt.LeftButton, pos=handle_pos)

    assert gslider._pressedControl == QStyle.SubControl.SC_None

    gslider.show()
    with qtbot.waitSignal(gslider.sliderPressed):
        qtbot.mousePress(gslider, Qt.LeftButton, pos=handle_pos)
Ejemplo n.º 2
0
def test_hover(gslider: QRangeSlider):

    hrect = gslider._handleRect(0)
    handle_pos = QPointF(gslider.mapToGlobal(hrect.center()))

    assert gslider._hoverControl == QStyle.SubControl.SC_None

    gslider.event(QHoverEvent(QEvent.HoverEnter, handle_pos, QPointF()))
    assert gslider._hoverControl == QStyle.SubControl.SC_SliderHandle

    gslider.event(
        QHoverEvent(QEvent.HoverLeave, QPointF(-1000, -1000), handle_pos))
    assert gslider._hoverControl == QStyle.SubControl.SC_None