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 still clickable with a rectangle in its way

MouseArea still clickable with a rectangle in its way

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 1.1k 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.
  • D Offline
    D Offline
    DavidM29
    wrote on last edited by DavidM29
    #1

    Hello,

    I just found out that when I use a mouse area and I put an Item in front of it using z axis I can still click on the mouse area through the Item.

    I would like to avoid this behaviour, how can I do that ?

    Here is a sample code where I should be able to display the Yellow rectangle but I should not be able to hide it.

        Rectangle{
            width: parent.width/2
            height: parent.height/2
            color: "blue"
            anchors.centerIn: parent
            z:0
            MouseArea{
                anchors.fill: parent
                onClicked: isVisible=!isVisible
                z:0
            }
        }
    
        Rectangle{
            width: parent.width/1.2
            height: parent.height/1.2
            anchors.centerIn: parent
            z:10
            visible: isVisible
            color: "yellow"
        }
    

    Thank you for your help in advance

    ODБOïO 1 Reply Last reply
    0
    • D DavidM29

      Hello,

      I just found out that when I use a mouse area and I put an Item in front of it using z axis I can still click on the mouse area through the Item.

      I would like to avoid this behaviour, how can I do that ?

      Here is a sample code where I should be able to display the Yellow rectangle but I should not be able to hide it.

          Rectangle{
              width: parent.width/2
              height: parent.height/2
              color: "blue"
              anchors.centerIn: parent
              z:0
              MouseArea{
                  anchors.fill: parent
                  onClicked: isVisible=!isVisible
                  z:0
              }
          }
      
          Rectangle{
              width: parent.width/1.2
              height: parent.height/1.2
              anchors.centerIn: parent
              z:10
              visible: isVisible
              color: "yellow"
          }
      

      Thank you for your help in advance

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @DavidM29 hi,
      I have never tested the effect of z property with MouseArea ..

      not sure this will really help you but

       MouseArea{
                  anchors.fill: parent
                  onClicked: isVisible=!isVisible
                  z:0
                  enabled: !isVisible // <-
              }
      
      1 Reply Last reply
      0
      • D Offline
        D Offline
        DavidM29
        wrote on last edited by DavidM29
        #3

        @LeLev
        Thank you for your reply,

        It should works with your example but I would like to avoid using this kind of solution because I'm having multiple "pop up" rectangles coming above some mouse area and I would like to avoid to set it like that :

        enable: !window1.isVisible || !window2.isVisible || windowXX.isVisible ....
        

        What I tried was this property but it does not seems to work for me

        propagateComposedEvents: false
        

        If you have any other ideas they are welcome

        1 Reply Last reply
        0
        • ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @DavidM29
          other idea : add a MouseArea to the 2nd Rectangle :

              Rectangle{
                  width: parent.width/1.2
                  height: parent.height/1.2
                  anchors.centerIn: parent
                  z:10
                  visible: isVisible
                  color: "yellow"
                  MouseArea{
                      anchors.fill: parent
                      
                  }
              }
          

          also see if QML Pupup type is suitable : https://doc.qt.io/qt-5/qml-qtquick-controls2-popup.html

              Rectangle{
                      width: parent.width/2
                      height: parent.height/2
                      color: "blue"
                      anchors.centerIn: parent
                      z:0
                      MouseArea{
                          anchors.fill: parent
                          onClicked: popup.open()
                          z:0
                      }
                  }
          
                Popup {
                    id: popup
                    width: parent.width/1.2
                         height: parent.height/1.2
                  x : 20
                  y :20
                    modal: true
                    focus: true
                    closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
          
                }
          
          D 1 Reply Last reply
          2
          • ODБOïO ODБOï

            @DavidM29
            other idea : add a MouseArea to the 2nd Rectangle :

                Rectangle{
                    width: parent.width/1.2
                    height: parent.height/1.2
                    anchors.centerIn: parent
                    z:10
                    visible: isVisible
                    color: "yellow"
                    MouseArea{
                        anchors.fill: parent
                        
                    }
                }
            

            also see if QML Pupup type is suitable : https://doc.qt.io/qt-5/qml-qtquick-controls2-popup.html

                Rectangle{
                        width: parent.width/2
                        height: parent.height/2
                        color: "blue"
                        anchors.centerIn: parent
                        z:0
                        MouseArea{
                            anchors.fill: parent
                            onClicked: popup.open()
                            z:0
                        }
                    }
            
                  Popup {
                      id: popup
                      width: parent.width/1.2
                           height: parent.height/1.2
                    x : 20
                    y :20
                      modal: true
                      focus: true
                      closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
            
                  }
            
            D Offline
            D Offline
            DavidM29
            wrote on last edited by
            #5

            @LeLev
            Thank you,
            I will take the second idea. I believe there is no other good way to do that.

            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