[PyQt] Working example of QMenuBar on OSX? Examples don't work

Marcel Maré list at webtothemax.com
Sun Jun 5 19:57:53 BST 2016


Hi

Think I found out some more. 

To rule out a programming error on my part (bering new to Qt) I only looked at the menus.py example (Qt/examples/mainwindows/menus.py). 

The relevant menu definition sections is like this:

def createMenus(self):
    self.fileMenu = self.menuBar().addMenu("&File")
    self.fileMenu.addAction(self.newAct)
    self.fileMenu.addAction(self.openAct)
    self.fileMenu.addAction(self.saveAct)
    self.fileMenu.addAction(self.printAct)
    self.fileMenu.addSeparator()
    self.fileMenu.addAction(self.exitAct)

    self.editMenu = self.menuBar().addMenu("&Edit")
    self.editMenu.addAction(self.undoAct)
    self.editMenu.addAction(self.redoAct)
    self.editMenu.addSeparator()
    self.editMenu.addAction(self.cutAct)
    self.editMenu.addAction(self.copyAct)
    self.editMenu.addAction(self.pasteAct)
    self.editMenu.addSeparator()

So, since it uses self.menuBar() it should not be compatible with the system menu on OSX, since it does not use QMenuBar(). 

Wat I found out that is that when I run the program the menu is visible but unclickable (as reported earlier). However, when I switch to some other program and then back to the menus.py program the menu works!
Looks like a bug to me.

Marcel 



> On 05 Jun 2016, at 18:42, David Cortesi <davecortesi at gmail.com> wrote:
> 
> I have a PyQt5 app that works well in Mac OS, Linux and Windows. The only difference I see in the setup of my QMainWindow is this:
> 
>         import platform
>         if platform.uname().system.startswith('Darw') :
>             self._menu_bar = QMenuBar() # parentless menu bar for Mac OS
>         else :
>             self._menu_bar = self.menuBar() # refer to the default one
> 
> and then it proceeds to initialize self._menu_bar with menus, e.g.
> 
>         self.file_menu = self._menu_bar.addMenu(_TR('Menu name', '&File'))
>         work = self.file_menu.addAction( _TR('File menu command','&New') )
>         work.setShortcut(QKeySequence.New)
>         work.setToolTip( _TR('File:New tooltip','Create a new, empty document') )
>         work.triggered.connect(self._new)
> 
> and so forth. The above test of platform.uname() is about the only platform difference in the whole app...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160605/41e4cb93/attachment.html>


More information about the PyQt mailing list