我目前正在尝试使用PyQt和QML。我添加了一个MenuBar,但它看起来像这样:
但我想要的是标准(取决于系统)菜单栏。我的main.py代码如下所示:
import sys
import PyQt5
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtQml
class NovaApp(QtGui.QGuiApplication):
"""the app self"""
def __init__(self, argv):
super(NovaApp, self).__init__(argv)
def main(argv):
app = NovaApp(sys.argv)
engine = QtQml.QQmlEngine(app)
component = QtQml.QQmlComponent(engine)
component.loadUrl(QtCore.QUrl("qml/window.qml"))
topLevel = component.create()
if topLevel is not None:
topLevel.show()
else:
for err in component.errors():
print(err.toString())
app.exec_()
if __name__ == '__main__':
main(sys.argv)
QML文件如下所示:
import QtQuick 2.0
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.0
import QtQuick.Dialogs 1.0
import QtQuick.Layouts 1.0
import QtGraphicalEffects 1.0
ApplicationWindow {
width: 800
height: 600
title: "Nova"
menuBar: MenuBar {
id: mainMenu
Menu {
title: "File"
MenuItem { text: "Open..." }
MenuItem { text: "Close" }
}
Menu {
title: "Edit"
MenuItem { text: "Cut" }
MenuItem { text: "Copy" }
MenuItem { text: "Paste" }
}
}
}
此致 扬