Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Non-Blocking mouse area that could receive mouse release event
Qt 6.12 LTS is out! See what's new in the release blog

Non-Blocking mouse area that could receive mouse release event

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.
  • benlauB Offline
    benlauB Offline
    benlau
    Qt Champions 2016
    wrote on last edited by
    #1

    Hi,

    I would like to make a mouse area which could receive mouse press and release event while it could propagate all the mouse event to its parent. So that It won't block any evens.

    I have tried to make a custom QQuickItem and reimplement the mousePressEvent() handler.

    void MouseSensor::mousePressEvent(QMouseEvent *event)
    {
       emit pressed(); 
       return QQuickItem::mousePressEvent(event);
    }
    

    It could receive mousePressEvent and propagate to its parent, but it won't receive mouseMouseEvent and mouseReleaseEvent. If I set accepted to true and don't call parent's mousePressEvent, then I could got the mouseReleaseEvent but it won't propagate events to parent.

    What could I do to make it propagate all the event to parent and it could receive mouseReleaseEvent?

    Thanks for any advise.

    1 Reply Last reply
    0
    • johngodJ Offline
      johngodJ Offline
      johngod
      wrote on last edited by
      #2

      According the MouseArea pressed event documentation:

      "If accepted is set to false, no further events will be sent to this MouseArea until the button is next pressed."

      Because of this you can't have a release event fired if you set in onPressed the mouse.accepted to false, because the signal is sent to the parent and there its were you will get the relese event fired.
      However there's a workaround, you can tell the parent release event to fire the child release event, see the next example:

      MouseArea {
              id:area1
              anchors.fill: parent
              onPressed: {
                  console.log("pressed on area1")
              }
              onReleased: {
                  console.log("released on area1")
                  area2.released(mouse)
              }
              MouseArea {
                  id: area2
                  anchors.fill: parent
      
                  propagateComposedEvents: true
                  onPressed: {
                      console.log("pressed on area2")
                      mouse.accepted = false
                  }
                  onReleased: {
                      console.log("released on area2")
                  }
              }
          }
      

      You should be able to do the same for mouse move events

      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
      • Unsolved