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:

Qt Code:
  1. QQuickView* pView = new QQuickView();
  2.  
  3. pView->setSource(QUrl("qrc:/MyRect.qml"));
  4. pView->setFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
  5. pView->setColor("transparent");
  6. pView->show();
To copy to clipboard, switch view to plain text mode 

MyRect.qml:

Qt Code:
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.4
  3.  
  4. Rectangle {
  5. width: 500
  6. height: 500
  7.  
  8. color: "green" // it would be transparent
  9. opacity: 0.5
  10.  
  11. Button {
  12. anchors.centerIn: parent
  13. height: 50; width: 50
  14. onClicked: console.log("clicked");
  15. }
  16.  
  17. MouseArea {
  18. anchors.fill: parent
  19. enabled: false
  20. propagateComposedEvents: true
  21. hoverEnabled: false
  22.  
  23. // All this code I think is useless...
  24. onClicked: mouse.accepted = false
  25. onReleased: mouse.accepted = false
  26. onEntered: mouse.accepted = false
  27. onExited: mouse.accepted = false
  28. onWheel: mouse.accepted = false
  29. }
  30. }
To copy to clipboard, switch view to plain text mode