【问题标题】:QML menu bar display in QtQuick applicationQtQuick 应用程序中的 QML 菜单栏显示
【发布时间】:2019-06-21 16:31:37
【问题描述】:

我正在使用 QML 开发一个仅包含一个菜单栏的 macOS 应用程序:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.4

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

    menuBar: MenuBar {
        Menu {
            title: qsTr("&File")
            Action { text: qsTr("&New...") }
            Action { text: qsTr("&Open...") }
            Action { text: qsTr("&Save") }
            Action { text: qsTr("Save &As...") }
            MenuSeparator { }
            Action { text: qsTr("&Quit") }
        }
        Menu {
            title: qsTr("&Edit")
            Action { text: qsTr("Cu&t") }
            Action { text: qsTr("&Copy") }
            Action { text: qsTr("&Paste") }
        }
        Menu {
            title: qsTr("&Help")
            Action { text: qsTr("&About") }
        }
    }
}

很遗憾,菜单看起来不像预期的那样:

通常,菜单项出现在 Apple 菜单旁边,此处仅包含 MenuTest

【问题讨论】:

  • 也许this 链接可能有用。

标签: macos qt menu qml


【解决方案1】:

您正在使用来自Controls 的“库存”菜单 - 它不是“原生”菜单。

您可以选择使用Qt.labs.platform提供的那个。

请记住,这会将 QtWidgets 模块作为项目依赖项拖动。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-18
  • 2011-07-27
  • 1970-01-01
  • 1970-01-01
  • 2015-03-05
  • 1970-01-01
相关资源
最近更新 更多