Results 1 to 15 of 15

Thread: ContextMenu Very unique GUI.

  1. #1
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default ContextMenu Very unique GUI.

    I want to know the secrets of the context menu, because it seems to have a lot of hidden things, that are not clearly shown. Some programs, have unique interfaces for rightclick context menus.

    An example is the image attached, it has like a sunken area with a gray background, where they just put some information about something.

    Another example is like some programs like DevC++ or MS Visual studio that have like large context menus with like icons on the left etc.

    I was wondering if anyone has any example code of how I can "tap into" these features.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ContextMenu Very unique GUI.

    Do I have to make my own PaintEvent and design it myself or something? How would I go bout doing this?

  3. #3
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ContextMenu Very unique GUI.

    I think you should take a close look to Qt sources...it should explain a lot.

    A context menu is just a QMenu displayed in a particular way, so there must be a particular painting method somewhere...I'll have a look

  4. #4
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ContextMenu Very unique GUI.

    Well I looked in QMenu and QPainter, but I still cannot tell how they get that gray area, and I'm wondering how I can code it.

  5. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ContextMenu Very unique GUI.

    QMenu can only contain menu items (QActions). That's the paradigm you have to live with when using QMenu. There is no way to create gray regions. However, you can create your own menu-like widget, and then draw it any way you want. That's probably what you want to do.

  6. #6
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ContextMenu Very unique GUI.

    Sounds difficult, but how the hell did they do it?
    Any ideas on how I should lay that class? What events to handle or what functions to use?

  7. #7
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ContextMenu Very unique GUI.

    Look at the QMenu code. That should give you all the information you need on creating your own QMenu-like class.

  8. #8
    Join Date
    Jan 2007
    Location
    Augsburg, Germany
    Posts
    75
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ContextMenu Very unique GUI.

    You can place widgets in menus (and also place a gray one )

    Qt Code:
    1. QMenu* myMenu = new QMenu(...);
    2. QLabel* label = new QLabel(tr("<b>Title</b>"), this);
    3. label->setAlignment( Qt::AlignCenter );
    4.  
    5. QWidgetAction* a = new QWidgetAction(myMenu);
    6. a->setDefaultWidget( label );
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to gri for this useful post:

    VireX (11th April 2007)

  10. #9
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ContextMenu Very unique GUI.

    That sounds promising... THANKS A LOT!!!

  11. #10
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ContextMenu Very unique GUI.

    One question why do we ever use "tr()"... what good does that do? Not only that it usually gives me compiler errors. I just remove it, because I don't see any point in using it.

  12. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: ContextMenu Very unique GUI.

    Quote Originally Posted by VireX View Post
    One question why do we ever use "tr()"... what good does that do? Not only that it usually gives me compiler errors. I just remove it, because I don't see any point in using it.
    Internationalization with Qt
    J-P Nurmi

  13. #12
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ContextMenu Very unique GUI.

    Quote Originally Posted by gri View Post
    Qt Code:
    1. QWidgetAction* a = new QWidgetAction(myMenu);
    To copy to clipboard, switch view to plain text mode 
    I didn't realize there was QWidgetAction. That's new in Qt 4.2. Thanks for the info.

  14. #13
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ContextMenu Very unique GUI.

    Its amazing, the only problem I had is, I could not change the background of a QLabel inside the QWidgetAction. I changed the QPalette::Window, but that didn't do the trick, then I tried a stylesheet, it worked fine in designer but once you add it to the ContextMenu it sets the background as the default gray for context menus.

  15. #14
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ContextMenu Very unique GUI.

    Hmm, still can't figure out a way to customize colors of conext menu, I tried Stylesheet on both QMenu and QLabel, but no luck, it changes fine in QDesigner but not when inside a context menu. Is there anyway to color the backgrounds of the context/qlabel stuff? I even tried QPainter.

  16. #15
    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: ContextMenu Very unique GUI.

    Please search the forum. The issue of changing the background of a QLabel has recently been brought up.

Similar Threads

  1. How to place contextmenu in QGraphicsScene?
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2007, 16:04
  2. contextmenu with MDI
    By Thoosle in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2006, 07:29
  3. MousePress Events on ContextMenu items
    By Naveen in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2006, 07:26
  4. ContextMenu
    By Naveen in forum Qt Programming
    Replies: 9
    Last Post: 21st February 2006, 10:54
  5. default contextMenu
    By Naveen in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2006, 14:44

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.