Results 1 to 8 of 8

Thread: Implement two menus at the same time!

  1. #1
    Join Date
    May 2012
    Posts
    11
    Qt products
    Qt4

    Default Implement two menus at the same time!

    minibar.png

    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?

    Qt Code:
    1. QMenu::exec(const QPoint &pos, QAction *at/* =0 */)
    2. {
    3. _menu.exec();
    4. }
    To copy to clipboard, switch view to plain text mode 

    I tried this codes, but I am failed.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Implement two menus at the same time!

    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
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2012
    Posts
    11
    Qt products
    Qt4

    Default Re: Implement two menus at the same time!

    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!

  4. #4
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Implement two menus at the same time!

    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 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 ).

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Implement two menus at the same time!

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Implement two menus at the same time!

    If one really wants, one can use show() instead of exec() however this is really counter-intuitive.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2012
    Posts
    11
    Qt products
    Qt4

    Default Re: Implement two menus at the same time!

    I can filter the mousemove and mousepressed event, however the event can not be dispatched any more. Any other ideas?

    Quote Originally Posted by wysota View Post
    If one really wants, one can use show() instead of exec() however this is really counter-intuitive.
    I tried this codes:
    Qt Code:
    1. void TwoMenu::contextMenuEvent(QContextMenuEvent *event)
    2. {
    3. _menu->popup(QCursor::pos());
    4. QSize size = _toolBar->sizeHint();
    5. _toolBar->move(QCursor::pos() - QPoint(0, size.height() + 5));
    6. _toolBar->show();
    7. }
    To copy to clipboard, switch view to plain text mode 
    At this time only one item can receive event. Is that I did wrong again?
    Last edited by high_flyer; 6th July 2012 at 09:41. Reason: code tags

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Implement two menus at the same time!

    I don't understand what you mean by

    Quote Originally Posted by koilin View Post
    At this time only one item can receive event.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 5
    Last Post: 19th November 2010, 02:25
  2. Replies: 6
    Last Post: 18th August 2010, 12:52
  3. Context Menus
    By qtoptus in forum Newbie
    Replies: 0
    Last Post: 25th June 2010, 15:18
  4. Context Menus
    By rodlbr in forum Qt Programming
    Replies: 4
    Last Post: 7th September 2009, 16:30
  5. using XML to save menus?!?!
    By nupul in forum Newbie
    Replies: 5
    Last Post: 7th April 2006, 09:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.