Esempio 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)
Esempio n. 2
0
def test_slider_extremes(gslider: QRangeSlider, mag, qtbot):
    _mag = 10**mag
    with qtbot.waitSignal(gslider.rangeChanged):
        gslider.setRange(-_mag, _mag)
    for i in _linspace(-_mag, _mag, 10):
        gslider.setValue((i, _mag))
        assert math.isclose(gslider.value()[0], i, rel_tol=1e-8)
        gslider.initStyleOption(QStyleOptionSlider())