在 QML 的菜单栏中插入文本

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

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

我想要以下内容:

https://img1.sycdn.imooc.com/65a91a2b00013ce703620022.jpg

该文本“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

            }

        }

    }


慕后森
浏览 52回答 1
1回答

慕森卡

可能有更漂亮的解决方案,但它可以通过在禁用的列表前面添加一个特殊的菜单项来工作。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"    }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript