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" } } }
效果图
![](https://i-blog.csdnimg.cn/blog_migrate/fc98f51a9b2141f3d97bdc8724a87390.png)