How to create a menu bar on OSX with PySide2?

别来无恙 提交于 2020-04-30 08:21:31

问题


I'm looking at the Data Visualization Tool Tutorial on the QT website where they have an example of creating a menu bar inside a QMainWindow:

self.menu = self.menuBar()
self.file_menu = self.menu.addMenu("File")

This doesn't work for me on OSX 10.13.6. I've also tried using QMenuBar to create my own menu bar rather than using the default one that comes with a QMainWindow:

menu_bar = QMenuBar()
menu_bar.addMenu('File')
self.setMenuBar(menu_bar)

This also has no effect. I never see the "File" option in the menu bar of my app. I just get a generic menu bar with a single "python" option.


回答1:


I believe it is working, but "File" will only appear once you add actions to the file menu.

menu = self.menuBar()
file = menu.addMenu('File')
file.addAction(QAction('Open...', self))


来源:https://stackoverflow.com/questions/60290777/how-to-create-a-menu-bar-on-osx-with-pyside2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!