为了账号安全,请及时绑定邮箱和手机立即绑定

在 QML 的菜单栏中插入文本

在 QML 的菜单栏中插入文本

慕后森 2024-01-18 20:31:18
这些菜单默认显示在左侧。我想在菜单开始出现之前在左侧放置一些文本。如何将菜单向右推以便为菜单栏中的文本创建空间?我想要以下内容:该文本“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            }        }    }
查看完整描述

1 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

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


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"

    }

}


查看完整回答
反对 回复 2024-01-18
  • 1 回答
  • 0 关注
  • 47 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信