我有一个鼠标区域。
MouseArea {
id: viewportMouseArea
// ...
}
收到信号后,我更改了光标shape:
onStatusChanged: {
viewportMouseArea.cursorShape = (myScene.status == MyScene.StatusForbidden) ? Qt.ForbiddenCursor : Qt.ArrowCursor
}
以上逻辑工作正常。
我打算更改逻辑,以便在接收到信号后,将光标形状更改为 1秒,然后在 1秒之后,恢复为默认光标形状。像这样的伪代码:
onStatusChanged: {
if ( myScene.status == MyScene.StatusForbidden ) {
for-1-second-do:
viewportMouseArea.cursorShape = Qt.ForbiddenCursor
After-1-second-do:
viewportMouseArea.cursorShape = Qt.ArrowCursor // default cursor shape
}
}
这样做的最佳实践是什么?
答案 0 :(得分:0)
我使用@eyllanesc建议的Timer实现了 1秒光标形状的更改。效果很好:
MyScene {
id: myScene
onStatusChanged: {
if ( myScene.Status === MyScene.StatusForbidden ) {
viewportMouseArea.cursorShape = Qt.ForbiddenCursor
timerForbidden.restart()
}
}
property Timer timer: Timer {
id: timerForbidden
interval: 1000 // milliseconds
running: false
repeat: false
onTriggered: { // triggered() signal is emitted when the Timer times out.
viewportMouseArea.cursorShape = Qt.ArrowCursor // Default cursor shape
}
}
}