Exemplo 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)
Exemplo n.º 2
0
def test_drag_handles(qtbot):
    rs = QRangeSlider(Qt.Horizontal)
    qtbot.addWidget(rs)
    rs.setRange(0, 99)
    rs.setValue((20, 80))
    rs.setMouseTracking(True)
    rs.show()

    # press the left handle
    pos = rs._handleRect(0).center()
    with qtbot.waitSignal(rs.sliderPressed):
        qtbot.mousePress(rs, Qt.LeftButton, pos=pos)
    assert rs._pressedControl == SC_HANDLE
    assert rs._pressedIndex == 0

    # drag the left handle
    with qtbot.waitSignals([rs.sliderMoved] * 13):  # couple less signals
        for _ in range(15):
            pos.setX(pos.x() + 2)
            qtbot.mouseMove(rs, pos)

    with qtbot.waitSignal(rs.sliderReleased):
        qtbot.mouseRelease(rs, Qt.LeftButton)

    # check the values
    assert rs.value()[0] > 30
    assert rs._pressedControl == SC_NONE

    # press the right handle
    pos = rs._handleRect(1).center()
    with qtbot.waitSignal(rs.sliderPressed):
        qtbot.mousePress(rs, Qt.LeftButton, pos=pos)
    assert rs._pressedControl == SC_HANDLE
    assert rs._pressedIndex == 1

    # drag the right handle
    with qtbot.waitSignals([rs.sliderMoved] * 13):  # couple less signals
        for _ in range(15):
            pos.setX(pos.x() - 2)
            qtbot.mouseMove(rs, pos)
    with qtbot.waitSignal(rs.sliderReleased):
        qtbot.mouseRelease(rs, Qt.LeftButton)

    # check the values
    assert rs.value()[1] < 70
    assert rs._pressedControl == SC_NONE
Exemplo n.º 3
0
def test_drag_handles_beyond_edge(qtbot):
    rs = QRangeSlider(Qt.Horizontal)
    qtbot.addWidget(rs)
    rs.setRange(0, 99)
    rs.setValue((20, 80))
    rs.setMouseTracking(True)
    rs.show()

    # press the right handle
    pos = rs._handleRect(1).center()
    with qtbot.waitSignal(rs.sliderPressed):
        qtbot.mousePress(rs, Qt.LeftButton, pos=pos)
    assert rs._pressedControl == SC_HANDLE
    assert rs._pressedIndex == 1

    # drag the handle off the right edge and make sure the value gets to the max
    for _ in range(7):
        pos.setX(pos.x() + 10)
        qtbot.mouseMove(rs, pos)

    with qtbot.waitSignal(rs.sliderReleased):
        qtbot.mouseRelease(rs, Qt.LeftButton)

    assert rs.value()[1] == 99
Exemplo n.º 4
0
from qtrangeslider import QRangeSlider
from qtrangeslider.qtcompat.QtCore import Qt
from qtrangeslider.qtcompat.QtWidgets import QApplication

app = QApplication([])

slider = QRangeSlider(Qt.Horizontal)
slider = QRangeSlider(Qt.Horizontal)

slider.setValue((20, 80))
slider.show()

app.exec_()
Exemplo n.º 5
0
def test_ticks(gslider: QRangeSlider, qtbot):
    gslider.setTickInterval(0.3)
    assert gslider.tickInterval() == 0.3
    gslider.setTickPosition(gslider.TicksAbove)
    gslider.show()