PDA

View Full Version : Caption in QMenu



Lykurg
10th April 2006, 11:09
Hi,

in Qt3's QPopupMenu one could insert a QLabel to get an Caption in a Menu. Qt4's QMenu is only providing a addAction(), which expects a QAction.
Is there any possibility to get an Caption in QMenu?


Thanks
Lykurg

wysota
12th April 2006, 11:57
Did you try the version of QMenu::addAction which takes a QString argument?

And you can always use QMenu::setTitle() to make a menu with a title.

Lykurg
13th April 2006, 06:14
Hi,

Did you try the version of QMenu::addAction which takes a QString argument?

as result I get an QAction:

myQMenu->addAction("some_text");
// is the same as:
QAction *act = new QAction(this);
act->setText("some_text");
myQMenu->addAction(act);

What I want is an "item", which is not clickable, checkable etc. and is not highlighted, when the cursor is above like the QActions. The "item" should be insert like an QAction, but behave like an QLabel. (It would be also nice when I could cusomize the frame...)


And you can always use QMenu::setTitle() to make a menu with a title.

QMenu::setTitle() is only internal, right? The title isn't displayed in the GUI.

Lykurg

wysota
13th April 2006, 11:05
What I want is an "item", which is not clickable, checkable etc. and is not highlighted, when the cursor is above like the QActions. The "item" should be insert like an QAction, but behave like an QLabel. (It would be also nice when I could cusomize the frame...)

The only thing you could do is to disable the action.



QMenu::setTitle() is only internal, right? The title isn't displayed in the GUI.

It isn't marked as internal in the docs. I think it should behave exactly like the previous snippet.

jdisrael
16th April 2014, 22:41
This is an old thread, but I came across it while searching so I thought I would update it with a solution.

You can use a QWidgetAction and then create a QLabel and set it with setDefaultWidget(). Then just add the QWidgetAction to the menu and you can style the QLabel freely.