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. QQuickView (QML) transparent for mouse events
Forum Updated to NodeBB v4.3 + New Features

QQuickView (QML) transparent for mouse events

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 776 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.
  • Diego DonateD Offline
    Diego DonateD Offline
    Diego Donate
    wrote on last edited by
    #1

    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->setSource(QUrl("qrc:/MyRect.qml"));
    pView->setFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    pView->setColor("transparent");
    pView->show();
    

    MyRect.qml:

    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
        }
    }
    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