Reputation: 327
My application can launch multiple instances of QMainWindow
, and I would like each instance to have the same menu. If there are no instances initialized but the application is still running (possible on Mac OS X), I would still like the same menu to be displayed but with a few items disabled.
How would I go about doing this? Would it work to subclass QMenu
or QMenuBar
, turn the subclass into a singleton, and pass that to each QMainWindow
?
Upvotes: 1
Views: 312
Reputation: 40512
QMenu
follows Qt's concept of ownage, and each menu or action can be owned only by one parent. There are ways to overcome that, but that wouldn't be the right thing to do. And subclassing can't change much in this case, especially not the ownage model.
I advise you to create a menu factory that creates separate menu and actions for each window (and one for no windows case) and connects each action to a corresponding slot (either in the window class or in some global class for global actions).
Upvotes: 2