I have ImageButton.qml which should change image when user holds the button.
import QtQuick 2.0
Image {
id: svg
property string idleImage
property string hoverImage
signal clicked
state: "idle"
source: state === "idle" ? idleImage : hoverImage
onSourceChanged: {
console.log("source = " + source)
}
MouseArea {
id: mouseArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onPressedChanged: {
svg.state = pressed ? "hover" : "idle"
}
onClicked: svg.clicked()
}
}
But the image is not changed immediately. It's changed only when I hold the button for several seconds. When I press and release mouse button immediately I never see the hover image. onSourceChanged is executed immediately and outputs to console the right image source. This strange bug happens only when I use QQuickWidget
. When I don't use widgets, but qml only everything works as expected.
I found the issue. I am using
QOpenGLWidget
in the MainWindow. And I called update method in paintGL.I replaced update call with a timer, running every 1000 / 60 milliseconds. And the issue was gone. It's strange that it was reproduced only when a mouse button was pressed, otherwise everything was updated correctly.