Qt C ++菜单栏没有在Windows上显示,但在Mac上显示

时间:2013-10-21 08:25:41

标签: c++ qt qml

我对Qt很新,我遇到了菜单问题。我刚从here复制了示例代码,并添加了一个周围的MenuBar-Tag

MenuBar{
Menu {
title: "Edit"

MenuItem {
    text: "Cut"
    shortcut: "Ctrl+X"
    onTriggered: console.log("test")
}

MenuItem {
    text: "Copy"
    shortcut: "Ctrl+C"
    onTriggered: console.log("test")
}

MenuItem {
    text: "Paste"
    shortcut: "Ctrl+V"
    onTriggered: console.log("test")
}

MenuSeparator { }

Menu {
    title: "More Stuff"

    MenuItem {
        text: "Do Nothing"
    }
}
}
}

在Mac上它可以正常工作但在Windows上我看不到任何菜单。有没有人有任何想法?

提前致谢!

1 个答案:

答案 0 :(得分:1)

如果要将菜单栏添加到窗口,则需要设置menuBar属性值。见this page

ApplicationWindow {
  id: window
  menuBar: MenuBar {
    Menu { MenuItem {...} }
    Menu { MenuItem {...} }
  }
}

可能在Mac上无关紧要,因为QMenuBar在Mac上的工作方式不同,并自动附加到Windows上。