简体   繁体   English

单击Qt窗口的菜单栏中的Python和文件,但在Mac OS上不起作用

[英]Click on Python and File in MenuBar of a Qt windows not working on Mac OS

I Have an issue on Mac OS when I try to click on my menubar, nothing happend. 当我尝试单击菜单栏时,在Mac OS上出现问题,什么也没发生。 I have two menus on named File and Load/Save but when I click on these the submenu don't show up. 我有两个名为“文件”和“加载/保存”的菜单,但是单击这些子菜单不会显示。 Although it works on windows and linux OS. 虽然它可以在Windows和Linux OS上运行。 So I'm suspecting something must be done for MAC, but I don't uberstand what? 因此,我怀疑必须对MAC做一些事情,但是我不理解是什么? Even clicking on the 'python' button don't do anything. 即使单击“ python”按钮也不起作用。

Here is a screenshot to better see what I meant: [![enter image description here][1]][1] 这是一个屏幕截图,可以更好地理解我的意思:[![在此处输入图片描述] [1]] [1]

and here the begining of the soft: 这是软件的开始:

class SurfViewer(QMainWindow):
    def __init__(self, parent=None):
        super(SurfViewer, self).__init__()
        self.parent = parent

        ############variable utiles###########
        self.height_per_line = 20
        self.height_add = 30
        self.width_per_col =155
        self.List_Stim = []
        self.NewStim = None
        self.List_ParamEvol = []
        self.NewParamEvol = None
        #######################################
        #######################################

        self.centralWidget = QWidget()
        self.color = self.centralWidget.palette().color(QPalette.Background) 


        # toolbarmenu
        extractAction = QAction("ScreenShot", self)
        extractAction.triggered.connect(self.screenshot)

        extractLoadmodelparam = QAction("Load Model parameters", self)
        extractSavemodelparam = QAction("Save Model parameters", self)
        extractLoadStimparam = QAction("Load Stimulation parameters", self)
        extractSaveStimparam = QAction("Save Stimulation parameters", self)
        extractLoadparamEvol = QAction("Load parameters evolution", self)
        extractSaveparamEvol = QAction("Save parameters evolution", self)
        self.extractLoadResult = QAction("Load Result signals", self)
        self.extractLoadResult.setEnabled(True)
        self.extractSaveResult = QAction("Save Result signals", self)
        self.extractSaveResult.setEnabled(False)

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(extractAction)
        fileLoad = menubar.addMenu('&Load/Save')
        fileLoad.addAction(extractSavemodelparam)
        fileLoad.addAction(extractLoadmodelparam)
        fileLoad.addAction(extractSaveStimparam)
        fileLoad.addAction(extractLoadStimparam)
        fileLoad.addAction(extractSaveparamEvol)
        fileLoad.addAction(extractLoadparamEvol)
        fileLoad.addAction(self.extractSaveResult)
        fileLoad.addAction(self.extractLoadResult)

        # set Tabs
        self.centralTabs= QTabWidget()
        self.setCentralWidget(self.centralTabs)

.... Some other stuffs after ....之后的其他一些东西

I finally found a solution. 我终于找到了解决方案。 Apparently, their is an issue with mac OS regarding to its way to handle menubar. 显然,对于Mac OS,其处理菜单栏的方式存在问题。 So I set the setNativMenuBar to false in the code: 因此,我在代码中将setNativMenuBar设置为false:

menubar.setNativeMenuBar(False)

Like that the menubar is still inside the windows (top left corner of the window) instead being at the top of the screen (detached from the software window itself) 这样,菜单栏仍位于窗口内(窗口左上角),而不是位于屏幕顶部(与软件窗口本身分离)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM