如何使用 PySide2 在 OSX 上创建菜单栏? [英] How to create a menu bar on OSX with PySide2?

查看:89
本文介绍了如何使用 PySide2 在 OSX 上创建菜单栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 数据可视化工具教程QT 网站,其中有一个在 QMainWindow 中创建菜单栏的示例:

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")

这在 OSX 10.13.6 上对我不起作用.我还尝试使用 QMenuBar 创建自己的菜单栏,而不是使用 QMainWindow 附带的默认菜单栏:

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)

这也没有效果.我从未在我的应用程序的菜单栏中看到文件"选项.我只是得到一个带有单个python"选项的通用菜单栏.

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.

推荐答案

我相信它是有效的,但是文件"只会在您向文件菜单添加操作后才会出现.

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))

这篇关于如何使用 PySide2 在 OSX 上创建菜单栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆