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. Why does a covered MouseArea still react

Why does a covered MouseArea still react

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 467 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.
  • P Offline
    P Offline
    poncho524
    wrote on last edited by
    #1

    I have one Rectangle filled with a MouseArea that gets covered by another Rectangle without a MouseArea, but the covered MouseArea still responds.

    Why does a covered element still get events? Is there a way to stop this?

    import QtQuick 2.0
    
    Rectangle {
      width: 300
      height: 200
      
      Rectangle {
        x: 0
        y: 0
        color: "red"
        width: 100
        height: 100
        MouseArea {
          anchors.fill: parent
          onPressed: {
            console.log("Pressed")
          }
          onReleased: {
            console.log("Released")
          }
        }
      }
      
      Rectangle {
        x: 0
        y: 0
        color: "blue"
        width: 100
        height: 100
      }
      
    }
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Rectangle is transparent to mouse events. It does not receive, handle or stop them.

      If you want to stop the covered area from getting mouse events, add another MouseArea in your top rectangle and catch the mouse there. Or disable the bottom mouse area (enabled: false) then the top rectangle is visible.

      (Z(:^

      1 Reply Last reply
      2

      • Login

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