Ejemplo n.º 1
0
def test_cursor_mixin(qtbot):
    @mixin.cursor_mixin
    class _TestClass(QPushButton):
        def __init__(self, parent=None):
            super(_TestClass, self).__init__(parent)
            geo = QApplication.desktop().screenGeometry()
            self.setGeometry(geo.width() / 4,
                             geo.height() / 4,
                             geo.width() / 2,
                             geo.height() / 2)

    main_widget = QWidget()
    button_test = _TestClass()
    button_normal = QPushButton()
    test_lay = QVBoxLayout()
    test_lay.addWidget(button_test)
    test_lay.addWidget(button_normal)
    main_widget.setLayout(test_lay)

    qtbot.addWidget(main_widget)
    main_widget.show()
    button_test.setEnabled(False)
    assert QApplication.overrideCursor() is None  # Not override cursor

    qtbot.mouseMove(button_test)  # mouse enter

    def check_cursor():
        assert QApplication.overrideCursor() is not None
        assert QApplication.overrideCursor().shape() == Qt.ForbiddenCursor

    qtbot.waitUntil(check_cursor)

    qtbot.mouseMove(button_normal)  # mouse leave

    def check_cursor():
        assert QApplication.overrideCursor() is None  # Restore override cursor

    qtbot.waitUntil(check_cursor)

    button_test.setEnabled(True)
    qtbot.mouseMove(button_test)  # mouse enter

    def check_cursor():
        assert QApplication.overrideCursor() is not None
        assert QApplication.overrideCursor().shape() == Qt.PointingHandCursor

    qtbot.waitUntil(check_cursor)

    qtbot.mouseMove(button_normal)  # mouse leave

    def check_cursor():
        assert QApplication.overrideCursor() is None  # Restore override cursor

    qtbot.waitUntil(check_cursor)
Ejemplo n.º 2
0
 def check_cursor():
     assert QApplication.overrideCursor() is None  # Restore override cursor
Ejemplo n.º 3
0
 def check_cursor():
     assert QApplication.overrideCursor() is not None
     assert QApplication.overrideCursor().shape() == Qt.PointingHandCursor
Ejemplo n.º 4
0
 def check_cursor():
     assert QApplication.overrideCursor() is not None
     assert QApplication.overrideCursor().shape() == Qt.ForbiddenCursor