QQuickView (QML) transparent for mouse events

  • I have a big rectangle with a button centered. I would like that my rectangle is transparent to mouse events except for the button, which must be clickable. I mean, I would like to be able to select code under my rectangle with the mouse, exactly as if no Rectangle was displayed.

    I have added a MouseArea for all the big Rect, trying to ignore mouse events, but it does not work.

    I read that 'Qt::WA_TransparentForMouseEvents' is used for that purpose, but in Qt windows as fasr as I know, not available in my case.

    Thanks in advance

    My QML is loaded from main.cpp:

    QQuickView* pView = new QQuickView();

    pView->setFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);


    import QtQuick 2.0
    import QtQuick.Controls 1.4
    Rectangle {
        width: 500
        height: 500
        color: "green" // it would be transparent
        opacity: 0.5
        Button {
            anchors.centerIn: parent
            height: 50; width: 50
            onClicked: console.log("clicked");
        MouseArea {
            anchors.fill: parent
            enabled: false
            propagateComposedEvents: true
            hoverEnabled: false
            // All this code I think is useless...
            onClicked: mouse.accepted = false
            onReleased: mouse.accepted = false
            onEntered: mouse.accepted = false
            onExited:  mouse.accepted = false
            onWheel:  mouse.accepted = false

Log in to reply