PDA

View Full Version : Implement two menus at the same time!



koilin
4th July 2012, 11:27
7947

I'd like to make a minibar like the one in this picture. This a context menu of Microsoft's word software, when you are right click on the pad, this context menu will show, MS call it minibar. This is actually two menu show at the same time. You know in out QT when you implement the QMenu.exec(), then the menu will to be modal, only this menu could accept event. Is there anyone could tell me a better way to exec two menu together?


QMenu::exec(const QPoint &pos, QAction *at/* =0 */)
{
_menu.exec();
}

I tried this codes, but I am failed.

high_flyer
4th July 2012, 11:36
This is actually two menu show at the same time.
Did you look in their code to know that?

Its more likely that the the upper one is a tool bar and the lower one a context menu.
QToolBar ,
QMenu

koilin
5th July 2012, 03:43
Although it looks like a toolbar plus a menu, and of course both of them can be show at the same time, once the menu is exec other widget can not get any message. I have tried eventFilter, the message can only be received one time, and can not dispatchered any more. Any other ideas? Thank you!

xtal256
5th July 2012, 05:20
Perhaps you could subclass QMenu to provide this enhanced functionality. I'm not sure exactly how it works, but i imagine that once the menu is popped up, it goes into some sort of event loop where it receives messages. If you could override this behaviour, you might be able to get and dispatch messages to the toolbar (which you would create as part of your QMenu subclass).

Again, i don't know how Qt does menus, but in the plain old Windows API you would call the TrackPopupMenu (http://msdn.microsoft.com/en-us/library/windows/desktop/ms648002.aspx) function to show the menu, then messages would be sent to the window procedure. I'm not sure if mouse move and click messages outside the menu are sent, but if they are then it would be possible to detect if a click was on a toolbar button. If not, then i don't know how Microsoft did it for their Office suite (perhaps some hackery :)).

high_flyer
5th July 2012, 10:37
once the menu is exec other widget can not get any message.
It sounds you have a design problem.
When a context menu is popped up, it is expected that the next thing you do is select and item in it, and not go do something else.
For the problem you posted in the first post, using a Tool bar would allow you to pop up a menu while the tool bar is still visible.
If this is not what you want, maybe you try and explain what it is you are trying achieve.

wysota
5th July 2012, 10:45
If one really wants, one can use show() instead of exec() however this is really counter-intuitive.

koilin
6th July 2012, 05:58
I can filter the mousemove and mousepressed event, however the event can not be dispatched any more. Any other ideas?


If one really wants, one can use show() instead of exec() however this is really counter-intuitive.

I tried this codes:

void TwoMenu::contextMenuEvent(QContextMenuEvent *event)
{
_menu->popup(QCursor::pos());
QSize size = _toolBar->sizeHint();
_toolBar->move(QCursor::pos() - QPoint(0, size.height() + 5));
_toolBar->show();
}
At this time only one item can receive event. Is that I did wrong again?

wysota
6th July 2012, 09:13
I don't understand what you mean by


At this time only one item can receive event.