Qt 6.11 is out! See what's new in the release
blog
QT6 hoverEnabled not working with an image
-
I have defined a simple Image that I want to rotate whenever someone hovers on it:
RotationAnimator { id: rotationAnimator from: 0; to: 360; duration: 1000 loops: Animation.Infinite } Image { Layout.preferredWidth: parent.width / 3 Layout.preferredHeight: Layout.preferredWidth id: options Layout.alignment: Qt.AlignBottom source: "../assets/options.png" fillMode: Image.PreserveAspectFit MouseArea{ anchors.fill: parent hoverEnabled: true Rectangle { anchors.fill: parent color: "red" opacity: 0.2 } onEntered:{ console.log("st"); rotationAnimator.target = parent; rotationAnimator.running = true; } onExited:{ rotationAnimator.running = false; } onClicked:{ stackView.push("Options.qml"); } } }It only rotates and prints whenever the left mouse button is pressed, despite hoverEnabled being set to true. Why? I also made rectangle to make sure the mousearea is correct and console.log to check if it's onEntered directly not working, and that's the case.
-
This works for me with Qt 6.5.3 on macOS.
import QtQuick import QtQuick.Window Window { visible: true RotationAnimator { id: rotationAnimator from: 0; to: 360; duration: 1000 loops: Animation.Infinite target: options } Image { id: options source: "https://ddgobkiprc33d.cloudfront.net/bfdb2533-84e9-45a1-956a-106722433d3f.png?v=ifu3inlhqv8" anchors.centerIn: parent MouseArea{ anchors.fill: parent hoverEnabled: true onEntered: rotationAnimator.running = true onExited: rotationAnimator.running = false } } }