python - 在应用程序顶部添加菜单栏
问题描述
我试图在应用程序的最顶部添加一个菜单栏,而不是它通常想要添加它的“内部”。
快速示例:
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QMenu
class Window(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("< Menu Go Here")
self.resize(400, 200)
self.centralWidget = QLabel("Hello, World")
self.centralWidget.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self.setCentralWidget(self.centralWidget)
self._createMenuBar()
def _createMenuBar(self):
menuBar = self.menuBar()
menuBar.addMenu(QMenu("&File", self))
menuBar.addMenu("&Edit")
menuBar.addMenu("&Help")
if __name__ == "__main__":
app = QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec_())
会创建类似的东西:
但是,我希望菜单成为其上方灰线的一部分(与图标和窗口标题相同的行)。
解决方案
推荐阅读
- docker - 启动 POD 时获取 ImagePullBackOff 是 AWS EKS
- python - 我将计数设置为 500 但 tweepy.cursor 仅返回 276 条推文,我如何获得 1000 多条推文?
- angular - 如何从一个组件获取值或数组到另一个组件而不以角度 8 存储在本地存储中
- c# - 初始化要并行执行的任务列表(对于 Task.WhenAll)的正确方法是什么?
- python - Pygame不能在Y轴上射击
- asp.net-core - 与部署在 IIS 中的多个子域站点共享相同的会话(aspnet 核心)
- javascript - 如何将数组添加到单个推送数据中?
- r - tidyeval 取消引用用户创建的变量以供后续使用
- javascript - Js Uncaught (in promise) DOMException 录制视频
- r - 使用 ifelse 创建新变量