在 QML 中渲染时遇到以下问题。我已经实现了“最小化窗口”按钮:
Image {
source: "minimize.png"
scale: mouse.pressed ? 0.8 : 1.0
smooth: mouse.pressed
MouseArea {
id: mouse
anchors.fill: parent
anchors.margins: -5
onClicked: {
console.log("MinimizeButton clicked");
viewer.showMinimized();
}
}
}
其中“查看器”是从 QDeclarativeView 继承的对象,它代表主应用程序窗口。当用户在其上单击鼠标并且窗口已最小化时,该按钮会缩小。但是当窗口恢复时按钮会保持收缩。尝试添加每 1 秒打印一次“mouse.pressed”的计时器:
Timer {
repeat: true
interval: 1000
running: true
onTriggered: {
console.log("mouse.pressed =",mouse.pressed);
}
}
它总是打印未按下鼠标。但是按钮缩放到 0.8,而不是 1.0。“viewer.showMinimized()”似乎是有罪的:如果注释掉按钮,它就会呈现正常。
有什么解决问题的建议吗?