Make window transparent to mouse events outside MouseAreas?



  • I know I might have some crazy ideas but I decide to share with you guys.

    Basically I'm making a frameless semi-transparent application with QML. There are some buttons based on MouseArea that I want to click. Besides the buttons are some other (semi-transparent) visual components but I want them to ignore any mouse events (so that I can click at other applications below them).

    Is this possible with the current QML framework (or in c++ side)?

    Things I've tried so far:

    • Qt.WA_TransparentForMouseEvents . This sadly make my window ignore all mouse events and there doesn't seem to be anyway to catch them.
    • setMask on QWindow or QQuickWidget. The mask can correctly limit mouse event capturing but it also crops all visual contents.

    Some sample code:

    import QtQuick 2.8
    
    Rectangle { // click through this
      color: Qt.rgba(1, 1, 1, 0.5)
    
      width: 640
      height: 480
    
      Rectangle { // click on this
        color: 'white'
        width: 50
        height: 50
        anchors.centerIn: parent
    
        MouseArea {
          anchors.fill: parent
          onClicked: console.log('click')
        }
      }
    }
    
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.