QML 右键菜单

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 1.4

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    MouseArea {
            id: mouseRegion
            anchors.fill: parent;
            acceptedButtons: Qt.LeftButton | Qt.RightButton

            onClicked: {
                if (mouse.button === Qt.RightButton) {
                    option_menu.popup()
                }
            }
        }

        Menu {
            id: option_menu

            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"
                }
            }
        }
}

qml 软件体系之  右键操作。

QML 右键菜单_第1张图片

你可能感兴趣的:(QT,Qml)