PDA

View Full Version : ContextMenu Very unique GUI.



VireX
10th April 2007, 02:37
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.

VireX
10th April 2007, 17:39
Do I have to make my own PaintEvent and design it myself or something? How would I go bout doing this?

guilugi
10th April 2007, 17:52
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

VireX
10th April 2007, 17:56
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.

Brandybuck
10th April 2007, 19:05
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.

VireX
10th April 2007, 20:06
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?

Brandybuck
10th April 2007, 21:14
Look at the QMenu code. That should give you all the information you need on creating your own QMenu-like class.

gri
11th April 2007, 09:38
You can place widgets in menus (and also place a gray one ;) )


QMenu* myMenu = new QMenu(...);
QLabel* label = new QLabel(tr("<b>Title</b>"), this);
label->setAlignment( Qt::AlignCenter );

QWidgetAction* a = new QWidgetAction(myMenu);
a->setDefaultWidget( label );

VireX
12th April 2007, 00:10
That sounds promising... THANKS A LOT!!!

VireX
12th April 2007, 18:11
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.

jpn
12th April 2007, 18:15
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 (http://doc.trolltech.com/4.2/i18n.html)

Brandybuck
12th April 2007, 19:33
QWidgetAction* a = new QWidgetAction(myMenu);

I didn't realize there was QWidgetAction. That's new in Qt 4.2. Thanks for the info.

VireX
12th April 2007, 22:08
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.

VireX
15th April 2007, 09:16
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.

wysota
15th April 2007, 09:45
Please search the forum. The issue of changing the background of a QLabel has recently been brought up.