Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] Prevent all mouse events from propagating to items below

    QML and Qt Quick
    3
    4
    4022
    Loading More Posts
    • 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.
    • Monomix
      Monomix last edited by

      Hello!

      Just getting properly into Qt Quick and QML now, the initial learning curve pain is subsiding. Alas, I have a question I thought I'd find an answer to with the power of Google, but couldn't find exactly what I was looking for.

      So: in a Qt Quick Components desktop app I have an overlay that I'm using with the rather nice "Progress Spinner":http://qt-project.org/wiki/QML_Progress_Spinner to indicate when the application is off doing stuff.

      When the app is off doing stuff, the overlay is shown over the whole window and I don't want any of the controls underneath to respond to any mouse events. At the moment, I've managed to inhibit button clicks but the elements underneath still respond to hover events (the buttons still show tooltips, the table view still highlights its header). How can I blanket prevent all mouse events from reaching the controls underneath?

      The code:
      @MouseArea {
      enabled: true
      width: parent.width
      height: parent.height
      z: parent.z
      propagateComposedEvents: false
      hoverEnabled: false
      preventStealing: true
      }@

      1 Reply Last reply Reply Quote 0
      • D
        dasRicardo last edited by p3c0

        Hello,

        the problem is you set hoverEnabled to false so your MouseArea doesn't catch this event so the event bubble down to other elements with mouse handling. I don't know if it's a bug. But here a working solution.

        ApplicationWindow {
            visible: true
            width: 640
            height: 480
            title: qsTr("Hello World")
            Rectangle {
                anchors.fill: parent
                color: 'red'
                Button {
                  width: 200
                  height: 100
                  text: "test"
                  onClicked: {
                    overlay.visible = true
                  }
                }
            }
            Rectangle {
              id: overlay
              z: 2
              color: "#aa000000"
              anchors.fill: parent
              MouseArea {
                anchors.fill: parent
                propagateComposedEvents: false
                hoverEnabled: true
                preventStealing: true
                onClicked: {
                  overlay.visible = false
                }
              }
            }
        }
        

        **Sorry for my english :)

        PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

        1 Reply Last reply Reply Quote 0
        • Monomix
          Monomix last edited by

          I like it when a solution is that simple. Thanks a lot!

          1 Reply Last reply Reply Quote 0
          • C
            CreMindES last edited by

            Thank you, I've just run into this problem!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post