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. Mouse Realease behavior...
Qt 6.11 is out! See what's new in the release blog

Mouse Realease behavior...

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.4k 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.
  • A Offline
    A Offline
    aekam
    wrote on last edited by
    #1

    @
    import QtQuick 1.0

    Item {
    width: 200
    height: 100

    Rectangle {
        id: rect1
        width: parent.width / 2
        height: parent.height
        anchors.left: parent.left
        color: "blue"
    
        MouseArea {
            anchors.fill: parent
    
            onPressed: {
                console.log ("rect1 pressed" +
                             " mouse x = " + mouseX +
                             " mouse y = " + mouseY)
            }
    
            onReleased: {
                console.log ("rect1 released" +
                             " mouse x = " + mouseX +
                             " mouse y = " + mouseY)
            }
        }
    }
    
    Rectangle {
        id: rect2
        width: parent.width / 2
        height: parent.height
        anchors.right: parent.right
        color: "yellow"
    
        MouseArea {
            anchors.fill: parent
    
            onPressed: {
                console.log ("rect2 pressed" +
                             " mouse x = " + mouseX +
                             " mouse y = " + mouseY)
            }
    
            onReleased: {
                console.log ("rect2 released" +
                             " mouse x = " + mouseX +
                             " mouse y = " + mouseY)
            }
        }
    }
    

    }
    @

    Hello,

    I wrote the above code, in which i am receiving a little strange behavior (for me, at least).
    I have two rectangles each contains mouse area with mouse pressed and mouse released slots.
    now if I press mouse in first rectangle, slot of mouse pressed of first rectangle gets call.
    but if i hold the press and release mouse in second rectangle still first rectangle receives mouse release event and its slot gets call.
    is this proper behavior.? as i was expecting mouse release event to be received from other rectangle.

    If you take care of inches, you won't have to worry about miles... :)

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dmcr
      wrote on last edited by
      #2

      Hello,

      actually the mouseReleased event happen on the object where the press was done.
      if you want to detect if the mouse is outside the element pressed
      you can for example use this
      @Rectangle{
      id : idTX
      anchor.fill:.....
      MouseArea{
      onMousePositionChanged:
      {
      if( mouse != null)
      {
      var okX = mouse.x > 0 && mouse.x < idTX.width
      var okY = mouse.y > 0 && mouse.y < idTX.height

                  if( !(okX && okY ) )
                      {/*here you are outside*/}
              }
          }
      }
      

      }@

      Edit :
      could use onExit of mousearea!

      dmcr

      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