[PyQt] accessing and modifying a menubar
dbeck at ualberta.ca
Tue Dec 2 21:21:22 GMT 2014
This may be a blindingly obvious question, but I have spent quite a bit of time trying to Google this problem and haven’t found an answer to it (maybe because I don’t know how to properly articulate the problem in technical talk).
I’m working on an application using QT 4.8, PyQt 4.11 and Python 3.4 on a Mac. I have a main window (we’ll call it “main_window”) layed out using QtDesigner that includes a menubar across the top of the screen which is set up to mimic the standard MacOS format (“File, Edit, etc.”). Under the “File” menu there is an “Open Recent” menu item that needs to be modified at various points while the programme is running (e.g., when a new file is opened, the file being closed needs to be added to the list). So, my question is basically, how do I access the menubar to modify it?
Things like “main_window.menuFile.menuOpen_Recent” (or variations on the theme) generate error messages telling me that main_window doesn’t have those attributes (that is, any of the menus or actions in the menubar). “main_window.menuBar()” creates a new menuBar that replaces what I had before rather than getting me a pointer to the existing menubar. From what I understand in the Qt documentation, this is probably because the menuBar isn’t a child of the main window—but then where is it and how do I access it?
Any help would be most appreciated.
More information about the PyQt