Checking mouse cursor shape or state (Qt)

Last edited on

Overview

There are two cursor types you can set in Qt, one is per application, and the other is for the current window.

Checking the application override mouse cursor

Checking the current shape

def main():
    ...

    if isNull(QApplication.overrideCursor()) or QApplication.overrideCursor().shape() != Qt.WaitCursor:
        test.fail("No or unexpected override cursor shape found")
    else:
        test.passes("Expected override cursor shape found")
test.py

An applications may only set an override cursor some time after it got started, so an immediate check might fail.

Waiting for a desired shape

def main():
    ...

    waitFor("isNull(QApplication.overrideCursor()) or QApplication.overrideCursor().shape() != Qt.WaitCursor")
test.py

Checking widget specific mouse cursor

Checking the current shape

def main():
    ...

    if waitForObject("object_name").cursor.shape() != Qt.WaitCursor):
        test.fail("Unexpected cursor shape found")
    else:
        test.passes("Expected cursor shape found")
test.py

(object_name must be a valid Squish object name.)

Waiting for a desired shape

def main():
    ...

    waitFor("waitForObject('object_name').cursor.shape() != Qt.WaitCursor")
test.py

(object_name must be a valid Squish object name.)