Gowtham
Gowtham

Reputation: 1475

How to style a submenu item in Qt?

I would like to style a menu item that has a submenu differently, just to make this submenu standout. But the style is being applied to the menu items in the submenu rather than styling the submenu item alone.

Menu1
Menu2 -> menu21
          menu22
          menu23
Menu3

I wanted to style only menu2, but Qt is styling menu21, menu22 and menu23.

Tried all these:

subMenu->setStyleSheet("QMenu{ font: bold }");
subMenu->setStyleSheet("QMenu::item{ font: bold }");
subMenu->setStyleSheet("QMenu::item#subMenu{ font : bold }");

Dynamic properties also did not help, setting a style on the action associated with subMenu is crashing Qt! :(

Thanks for your time,

Gowtham

Upvotes: 2

Views: 4052

Answers (2)

Knitschi
Knitschi

Reputation: 3102

I would put this in a comment, but I have no right to add comments :-(

The links provided by Daggerstab did not work for me. Here is another one to an example for customizing QMenu

Upvotes: 0

Daggerstab
Daggerstab

Reputation: 623

See the documentation:

I haven't tested this, but in theory, you may be able to use QMenu::item with either a Property Selector or a ID Selector (see Qt Style Sheet Syntax - Selectors). For example:

QMenu::item[text="Menu2 text"]

or

QMenu::item#menu2Id

though it may be difficult to get or set the ID.

Of course, it may turn out that it's impossible to set individual styles for QMenu entries outside of the cases shown in the Qt examples.

Upvotes: 2

Related Questions