【问题标题】:PySide MainWindow doesn't create Menu BarPySide MainWindow 不创建菜单栏
【发布时间】:2015-07-24 01:18:22
【问题描述】:

我正在尝试在 MainWindow 小部件上创建 menuBar,但是在编写了我在互联网上找到的代码后,似乎什么也没发生,菜单栏没有创建,即使没有错误消息显示出来。

我用来创建带有菜单栏的 UI 的代码如下:

def initUI(self):

    QToolTip.setFont(QFont("SansSerif", 10))

    self.setCentralWidget(QWidget())

    #Create the action to use on the menu bar
    exitAction = QAction(QIcon("logo.png"), "&Exit", self)
    exitAction.setShortcut("Cmd+Q")
    exitAction.setStatusTip("Close the application.")
    exitAction.triggered.connect(self.close)

    #Create status bar
    self.statusBar()

    #Attempt to create menu bar, but nothing happens.
    menuBar = self.menuBar()
    fileMenu = menuBar.addMenu("&File")
    fileMenu.addAction(exitAction)

    #Set MainWindow properties.
    self.setGeometry(0, 0, 250, 150)
    self.setWindowTitle("Icon")
    self.setWindowIcon(QIcon("logo.png"))
    self.setToolTip("This is the <b>Main Window</b>.")

    self.show()

编辑:我正在使用 OSX。

【问题讨论】:

    标签: python pyside qmainwindow qmenubar


    【解决方案1】:

    好吧,看来问题是我使用的是 OSX,它们会过滤一些关键字。

    如需更详细的答案,请查看此答案,因为它已向我解释: Why doesn't menu get added?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 2015-04-01
      • 1970-01-01
      相关资源
      最近更新 更多