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. QML Image MouseArea onClicked not working

QML Image MouseArea onClicked not working

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 3.4k Views 3 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I have a QML file, there is an image:

    Image {
        id: iconLocal
        anchors.right: parent.right
        source: "images/fake assets/arrow_right_green.png"
        width: 64; height: 64
        opacity: 0.7
        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            acceptedButtons: Qt.LeftButton
            onClicked: {
                 console.log("Clicked");
            }
            onEntered: {
                iconLocal.opacity = 1.0;
            }
            onExited: {
                iconLocal.opacity = 0.7;
            }
        }
    }
    

    When the mouse is hovered over the image and moved out I can see that the image opacity is changing, but nothing happens when the image is clicked.

    What could explain why the onClicked isn't working?

    Kind Regards,
    Sy

    J.HilkJ 1 Reply Last reply
    0
    • SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #6

      I've now sorted this out, the issue was caused by using Qt.LeftButton, this has been replaced with Qt.AllButtons and now it works perfectly.

      Kind Regards,
      Sy

      ODБOïO 1 Reply Last reply
      0
      • P Offline
        P Offline
        poucz
        wrote on last edited by
        #2

        Hellos,

        You have mishmash in name of element "iconLabel" vs "iconLocal".
        When I fix this code is working - opacity is change when I hover in or out, and when I click by left button console log appear.
        I used:

        import QtQuick 2.7
        import QtQuick.Controls 2.0
        import QtGraphicalEffects 1.0
        
        ODБOïO SPlattenS 2 Replies Last reply
        1
        • P poucz

          Hellos,

          You have mishmash in name of element "iconLabel" vs "iconLocal".
          When I fix this code is working - opacity is change when I hover in or out, and when I click by left button console log appear.
          I used:

          import QtQuick 2.7
          import QtQuick.Controls 2.0
          import QtGraphicalEffects 1.0
          
          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #3

          @poucz said in QML Image MouseArea onClicked not working:

          mishmash in name of element "iconLabel" vs "iconLocal".

          i guess that is a typo because

          @SPlatten said in QML Image MouseArea onClicked not working:

          When the mouse is hovered over the image and moved out I can see that the image opacity is changing

          ...

          1 Reply Last reply
          0
          • P poucz

            Hellos,

            You have mishmash in name of element "iconLabel" vs "iconLocal".
            When I fix this code is working - opacity is change when I hover in or out, and when I click by left button console log appear.
            I used:

            import QtQuick 2.7
            import QtQuick.Controls 2.0
            import QtGraphicalEffects 1.0
            
            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by SPlatten
            #4

            @poucz , Sorry that isn't the problem just my incompetence at typing the data into here....As I said those bits work.

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • SPlattenS SPlatten

              I have a QML file, there is an image:

              Image {
                  id: iconLocal
                  anchors.right: parent.right
                  source: "images/fake assets/arrow_right_green.png"
                  width: 64; height: 64
                  opacity: 0.7
                  MouseArea {
                      anchors.fill: parent
                      hoverEnabled: true
                      acceptedButtons: Qt.LeftButton
                      onClicked: {
                           console.log("Clicked");
                      }
                      onEntered: {
                          iconLocal.opacity = 1.0;
                      }
                      onExited: {
                          iconLocal.opacity = 0.7;
                      }
                  }
              }
              

              When the mouse is hovered over the image and moved out I can see that the image opacity is changing, but nothing happens when the image is clicked.

              What could explain why the onClicked isn't working?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #5

              @SPlatten Maybe you have an other MouseArea on top of this item? I think the hover event is propagated automatically, the clicked (pressed and release) is not


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              2
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #6

                I've now sorted this out, the issue was caused by using Qt.LeftButton, this has been replaced with Qt.AllButtons and now it works perfectly.

                Kind Regards,
                Sy

                ODБOïO 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  I've now sorted this out, the issue was caused by using Qt.LeftButton, this has been replaced with Qt.AllButtons and now it works perfectly.

                  ODБOïO Offline
                  ODБOïO Offline
                  ODБOï
                  wrote on last edited by ODБOï
                  #7

                  @SPlatten said in QML Image MouseArea onClicked not working:

                  I've now sorted this out, the issue was caused by using Qt.LeftButton, this has been replaced with Qt.AllButtons and now it works perfectly.

                  So you were Right-clicking ?

                  Your code works just fine even with Qt.LeftButton, if you click the left button and there is no other mouseArea overlapping the first one ...

                  1 Reply Last reply
                  0
                  • SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #8

                    No left!

                    Kind Regards,
                    Sy

                    ODБOïO 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      No left!

                      ODБOïO Offline
                      ODБOïO Offline
                      ODБOï
                      wrote on last edited by
                      #9

                      @SPlatten ok, I'm glad you solved the issue.

                      but normally accepted Buttons: Qt.LeftButton should accept left clicks

                      SPlattenS 1 Reply Last reply
                      0
                      • ODБOïO ODБOï

                        @SPlatten ok, I'm glad you solved the issue.

                        but normally accepted Buttons: Qt.LeftButton should accept left clicks

                        SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by
                        #10

                        @LeLev Thank you.

                        Kind Regards,
                        Sy

                        1 Reply Last reply
                        1

                        • Login

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