Hi all.  I have a Qt Widgets based app that runs on both macOS and Linux.  So 
far, it has only had one kind of “main window”, with a menu bar of its own.  On 
macOS I want the app to look native, with a global menu bar at the top of the 
screen; on Linux, at least on the Linux variants I’m familiar with, each main 
window has its own menus.  I’ve got all of this working nicely, after a bit of 
struggle.

Now, however, I’d like to add a second type of “main window”, representing a 
different type of document that the app can also open/edit.  On macOS changing 
the contents of the global menu bar is frowned upon; you’re supposed to just 
enable/disable menu items depending upon whether they apply in the current 
context.  I’d like to do things that way, although it might feel a little bit 
odd on Linux.  So I want the menu bar of the new document type to be the same 
as the menu bar of the original document type, just enabled/disabled 
differently (mostly disabled).

My question is what the graceful way is to do this.  At present, the .ui file 
for the original document window contains a QMenuBar inside it, representing 
the global menu bar.  The new document type will have its own .ui file, though, 
since its window will be quite different.  One option would be to just 
duplicate the whole menu bar across the two nib files, so both .ui files have 
identical menu bar setups.  That’s ugly, and a maintenance headache, though.  
Other options would perhaps be:

- Have both main windows inherit from a common superclass that provides the 
menu bar, read from a separate .ui file.  I’m not sure how to do this, though.

- Have both main windows read in a .ui file containing the menu bar, and 
integrate it into their window (similar to the first option, but without the 
common superclass).  Not sure how to do this either.

- Maybe some other approach that I haven’t thought of?

It does make sense to me for both main windows to inherit from a common base 
class; there is a fair amount of app-level logic that needs to 
find/query/message the current main window, whichever type of main window it 
might happen to be.  (For a modeless Find panel in my app, for example.)  But 
how should I handle reading in a menu-bar-only .ui file and integrating that 
menu bar into the window read from a different .ui file?

Thanks for any help.

Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to