PDA

View Full Version : Context Menu's submenu doesn't appear



DancingFirefly
19th August 2009, 21:32
I've run into an odd error:

I have a context menu (handled with my own class's contextMenuEvent method) which pops up just fine. I've pre-populated that context menu with actions at creation time, and so it works just great.

Then I decided I needed to add a submenu with its own QActions.

I am using QMenu for the context menu, but a subclass of QMenu for the submenu, because I wish to dynamically repopulate the submenu's actions depending on what was selected.

I connected the context menu's aboutToShow() signal to a slot in my submenu derived class. I see that the slot does execute when I hover the mouse over the menuAction of the submenu. I see that my logic for creating and adding the actions (with addAction()) does work correctly. However, I never see the submenu appear!

In regards to how I subclass QMenu... it's publicly inherited and I don't override any methods (certainly no non-virtual methods!).

I only create a singleton of this QMenu derived class, though. I add it to my context menus for each of my application's views via addMenu(QMenu*). I knew about the menuAction of the QMenu derived class so in addition to setting up the QMenu derived class's statusTip, objectName and title, I also set up the menuAction's text, statusTip and objectName. But in addition to the submenu with the populated actions never showing...I never can get the status bar to show the associated message! I even went out of my way to connect() the hovered() signal of the menuAction to a statusBarEvent() slot I made to send the event to the statusBar.

I know some of you will probably suggest I not create a singleton of the QMenu derived class. Why? Is there some reason why that might create a problem with Qt4.5? If not, I am going to do it this way as it is a cleaner design for my project. I have to use this same QMenu derived class in no less than six different places in the code and it makes more sense to create it and set it up once and reuse the pointer.

Please advise! I'm at my wit's end...

~Firefly