這是一些簡單的QML代碼,它包含一個Button
和一個MouseArea
。我想Button
檢測到鼠標左鍵和右鍵點擊。QML MouseArea重疊其他小工具
Rectangle {
anchors.fill:parent;
width: 1302
height: 638
Button {
id: button1
x: 378
y: 332
width: 194
height: 66
text: qsTr("Button")
}
MouseArea {
id: mouseArea1
x: 368
y: 306
width: 226
height: 108
acceptedButtons: Qt.RightButton
propagateComposedEvents: true
onClicked: {
console.log("Click")
mouse.accepted = false
}
}
}
由於MouseArea
定位在Button
的頂部,我怎麼能強迫Button
接受鼠標事件?
「按鈕」中沒有任何點擊處理程序。你如何得到迴應?不要同時使用'anchors.fill'和'width' /'height'。如果你真的想重疊一個表面與另一個表面,使用'z'。而且據我所知'Button'不響應右鍵單擊。你究竟在這裏做什麼? – folibis 2015-02-23 22:43:08
我想要在右鍵單擊某個按鈕時彈出一個上下文菜單。 – illunara 2015-02-24 03:01:37
但更重要的是,當我們放在它們的頂部時(如tableView,textEditor .....),MouseArea會獲取其他小部件的所有mouseEvent。我如何解決它? – illunara 2015-02-24 03:20:25