Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT6 hoverEnabled not working with an image
Qt 6.11 is out! See what's new in the release blog

QT6 hoverEnabled not working with an image

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 329 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    roditu
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      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
              }
          }
      }
      

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved