我有一个大矩形,按钮居中。我希望我的矩形对鼠标事件是透明的,除了按钮,它必须是可点击的。我的意思是,我希望能够用鼠标选择矩形下的代码,就像没有显示矩形一样。
我为所有大矩形添加了一个 MouseArea,试图忽略鼠标事件,但它不起作用。
我读到'Qt :: WA_TransparentForMouseEvents'用于此目的,但据我所知,在Qt窗口中,在我的情况下不可用。
提前致谢
我的 QML 是从 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
}
}