检查鼠标光标形状或状态(Qt)

最后编辑了

概述

您可以在Qt中设置两个光标类型,一个是每个应用程序,另一个是当前窗口。

检查应用程序覆盖鼠标光标

检查当前的形状

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.

应用程序可能只在启动后设置覆盖光标,因此立即检查可能会失败。

等待所需的形状

def main():
    ...

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

检查小部件特定的鼠标光标

检查当前的形状

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.)

等待所需的形状

def main():
    ...

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

(object_name must be a valid Squish object name.)