Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在QML的菜单栏中插入文本_Javascript_Qt_Qml - Fatal编程技术网

Javascript 在QML的菜单栏中插入文本

Javascript 在QML的菜单栏中插入文本,javascript,qt,qml,Javascript,Qt,Qml,默认情况下,这些菜单显示在左侧。我想在菜单开始出现之前在左侧放置一些文本 如何将菜单向右推,以便为菜单栏中的文本创建空间 我想要以下内容: “AmplifyRemote”文本在菜单启动之前出现。如何在这里实现这一点 ApplicationWindow { id: window; visible: true; width: Screen.width; height: Screen.height; flags: Qt.FramelessWindowHint menuBar:

默认情况下,这些菜单显示在左侧。我想在菜单开始出现之前在左侧放置一些文本

如何将菜单向右推,以便为菜单栏中的文本创建空间

我想要以下内容:

“AmplifyRemote”文本在菜单启动之前出现。如何在这里实现这一点

ApplicationWindow
{
    id: window; visible: true; width: Screen.width; height: Screen.height; flags: Qt.FramelessWindowHint

    menuBar:
      MenuBar
      {
        id: menuBar

        Menu { title: qsTr("File") }
        Menu { title: qsTr("Edit") }
        Menu { title: qsTr("View") }
        Menu { title: qsTr("Help") }

        delegate: MenuBarItem {
            id: menuBarItem

            font
            {
                pointSize: decoration.font_size_8
                family: decoration.font_family
            }
            contentItem: Text {
                text: menuBarItem.text
                font: menuBarItem.font
                opacity: enabled ? 1.0 : 0.3
                color: menuBarItem.highlighted ? "white":"#3F3F3F"
                horizontalAlignment: Text.AlignLeft
                verticalAlignment: Text.AlignVCenter
                elide: Text.ElideRight
            }

            background: Rectangle {
                implicitWidth: 40
                implicitHeight: 40
                opacity: enabled ? 1 : 0.3
                color: menuBarItem.highlighted ? "#292a38" : "transparent"
            }
        }

        background: Rectangle {
            implicitWidth: 40
            implicitHeight: 11
            color: "#d2d2d2"

            // This is the text I want before menus start
            Text{ text:"jjjjjjjjj"; anchors.left: parent.left}    

            Rectangle {
                color: "#21be2b"
                width: parent.width
                height: 1
                anchors.bottom: parent.bottom
            }
        }
    }
}

可能有更漂亮的解决方案,但可以通过在列表前面添加一个禁用的特殊菜单项来实现

MenuBar {
    id: menuBar

    Menu { title: "jjjjjjjj" }
    Menu { title: qsTr("File") }
    Menu { title: qsTr("Edit") }
    Menu { title: qsTr("View") }
    Menu { title: qsTr("Help") }

    delegate: MenuBarItem {
        id: menuBarItem

        enabled: text !== "jjjjjjjj"
    }
}

可能有更漂亮的解决方案,但可以通过在列表前面添加一个禁用的特殊菜单项来实现

MenuBar {
    id: menuBar

    Menu { title: "jjjjjjjj" }
    Menu { title: qsTr("File") }
    Menu { title: qsTr("Edit") }
    Menu { title: qsTr("View") }
    Menu { title: qsTr("Help") }

    delegate: MenuBarItem {
        id: menuBarItem

        enabled: text !== "jjjjjjjj"
    }
}

与其将您的特殊文本添加为背景的一部分,您是否可以将其添加为另一个禁用的菜单项,以使其无法被选择?请说明如何执行此操作@Jarman与其将您的特殊文本添加为背景的一部分,不如将其添加为另一个被禁用的菜单项,以使其无法被选择?请说明如何进行此操作@贾曼