代码之家  ›  专栏  ›  技术社区  ›  Gustavo Amgarten

PySide主窗口不创建菜单栏

  •  1
  • Gustavo Amgarten  · 技术社区  · 9 年前

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

    我使用菜单栏创建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。

    1 回复  |  直到 9 年前
        1
  •  0
  •   Community CDub    8 年前

    好的,问题是我使用的是OSX,他们过滤了一些关键词。

    要获得更详细的答案,请检查这个,因为它向我解释了这一点: Why doesn't menu get added?