PyQT5菜单不可见

时间:2015-05-19 11:59:40

标签: qt menu qt5 pyqt5

执行这个小PyQT5脚本时,我看不到菜单;它只是在ubuntu 14.04上显示一个空窗口(没有错误或警告)。

from PyQt5 import QtWidgets

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MainWindow,self).__init__()
        self.createUI()

    def doAction(self):
        print('action')

    def createUI(self):
        self.setWindowTitle('Test')
        menu   = self.menuBar().addMenu('File')
        action = menu.addAction('Action')
        action.triggered.connect(self.doAction)   


if __name__ == '__main__':

    import sys
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    window.show()
    window.setGeometry(400, 200, 200, 200)
    sys.exit(app.exec_())

有什么想法吗?

1 个答案:

答案 0 :(得分:7)

我遇到了同样的问题 尝试将本机菜单栏标记设置为false,如下所示:

menu.setNativeMenuBar(False)
相关问题