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. MouseArea behind another control

MouseArea behind another control

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 444 Views
  • 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.
  • K Offline
    K Offline
    krobinson
    wrote on last edited by
    #1

    I have a scenario where I have a MouseArea that I am covering with another control. The issue is that it doesn't disable the clicked event. You can just click "through" the covering control. Is there any way to fix this? Is there a way in the onClicked to tell if the MouseArea is visible? Here is an example.

    import QtQuick 2.9
    import QtQuick.Controls 2.2
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle {
            color: "red"
            anchors.fill: parent
            MouseArea {
                anchors.left: parent.left
                anchors.top: parent.top
                width: 100
                height: 100
                onClicked: console.debug("clicked")
    
            }
        }
        Rectangle {
            color: "blue"
            anchors.fill: parent
    
        }
    }
    
    DiracsbracketD 1 Reply Last reply
    0
    • K krobinson

      I have a scenario where I have a MouseArea that I am covering with another control. The issue is that it doesn't disable the clicked event. You can just click "through" the covering control. Is there any way to fix this? Is there a way in the onClicked to tell if the MouseArea is visible? Here is an example.

      import QtQuick 2.9
      import QtQuick.Controls 2.2
      import QtQuick.Window 2.2
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Rectangle {
              color: "red"
              anchors.fill: parent
              MouseArea {
                  anchors.left: parent.left
                  anchors.top: parent.top
                  width: 100
                  height: 100
                  onClicked: console.debug("clicked")
      
              }
          }
          Rectangle {
              color: "blue"
              anchors.fill: parent
      
          }
      }
      
      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      @krobinson
      You can simply intercept and ignore the mouse events inside the blue rectangle:

          Rectangle {
              color: "blue"
              anchors.fill: parent
              MouseArea {
                  anchors.fill: parent
              }
          }
      
      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