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. Clicks go throught item, how to stop?

Clicks go throught item, how to stop?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 704 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.
  • Z Offline
    Z Offline
    zizzu
    wrote on last edited by
    #1

    Hello could someone explain me how do i stop this beavior?

    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle {
            id: bo1
            color: "blue"
            anchors.fill: parent
    
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    console.log("CLICKED")
                }
            }
        }
    
        Rectangle {
            id: bo2
            color: "green"
            anchors.fill: parent
            z: 1
            focus: true
    
            Rectangle {
                color: "red"
                id: removeButton
                anchors.centerIn: parent
                width: height
                height: 50
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        bo2.destroy()
                    }
                }
            }
        }
    }
    

    If i click on the green rectangle the mouse area in the blue rectangle respond to the click. I want to click on the green without the blue responding, thank you.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Just add another MouseArea to the green Item:

      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Rectangle {
              id: bo1
              color: "blue"
              anchors.fill: parent
      
              MouseArea {
                  anchors.fill: parent
                  onClicked: {
                      console.log("CLICKED")
                  }
              }
          }
      
          Rectangle {
              id: bo2
              color: "green"
              anchors.fill: parent
              z: 1
              focus: true
      
              MouseArea {
                  // THIS WILL CONSUME ALL CLICKS ON GREEN
                  anchors.fill: parent
              }
      
              Rectangle {
                  color: "red"
                  id: removeButton
                  anchors.centerIn: parent
                  width: height
                  height: 50
                  MouseArea {
                      anchors.fill: parent
                      onClicked: {
                          bo2.destroy()
                      }
                  }
              }
          }
      }
      
      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zizzu
        wrote on last edited by
        #3

        Hello yes that could be 1 solution but i have an item on top of others which i need to interact with (clicks etc), so i wrote a javascript function, like, if the green rect is showing (which is a form for real), all the others items under it are disabled.

        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