Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Mouse onReleased Happening before onClicked(Solved)
Forum Updated to NodeBB v4.3 + New Features

QML Mouse onReleased Happening before onClicked(Solved)

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 2.9k 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.
  • H Offline
    H Offline
    haris123
    wrote on last edited by
    #1

    Below is my code, what I want to do is change color of button while clicking and releasing button.
    But it seems that onReleased Happening before onClicked when I print to console.

    @MouseArea{
                     anchors.fill: parent
                     onClicked:{
                         console.log("onClicked")
    
                         //Change button  color here
                        
    
                     }
                     onReleased: {
                         console.log("onReleased")
                       //Change button color here to another
    
                     }
                }
    

    @

    Console output
    @qml: onReleased
    qml: onClicked@

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      According to "clicked":http://qt-project.org/doc/qt-5/qml-qtquick-mousearea.html#clicked-signal, release will first be fired and then click. So a better way would be to use pressed.

      157

      1 Reply Last reply
      0
      • H Offline
        H Offline
        haris123
        wrote on last edited by
        #3

        Hi, thanks for reply,

        but how can I get unclick event?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          You need to use onPressed instead of onClicked.

          (Z(:^

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            bq. but how can I get unclick event?

            Sorry, didn't understand unclick event. Can you explain ? Won't onPressed be helpful to your scenario ?

            157

            1 Reply Last reply
            0
            • H Offline
              H Offline
              haris123
              wrote on last edited by
              #6

              I mean release mouse button.

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

                You must use onPressed or don't use onReleased when using onClicked.

                157

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  haris123
                  wrote on last edited by
                  #8

                  Ok, thank you all, I will do it.

                  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