添加右键菜单功能小案例
MouseArea {
id: mouseRegion
anchors.fill: parent;
acceptedButtons: Qt.LeftButton | Qt.RightButton // 激活右键(别落下这个)
onClicked: {
if (mouse.button === Qt.RightButton) { // 右键菜单
//
contentMenu.popup()
}
}
}
Menu { // 右键菜单
title: "Edit"
id: contentMenu
MenuItem {
text: "Cut"
shortcut: "Ctrl+X"
onTriggered: {}
}
MenuItem {
text: "Copy"
shortcut: "Ctrl+C"
onTriggered: {}
}
MenuItem {
text: "Paste"
shortcut: "Ctrl+V"
onTriggered: {}
}
MenuSeparator { }
Menu {
title: "More Stuff"
MenuItem {
text: "Do Nothing"
}
}
}