Customize the style of a single menubar item?
-
Hi there,
We have a widget called 'Workbench selector'. This is basically a combobox that allow the user to select a workbench. (see below picture)This is currently implemented as a widget in the toolbars area. However we want to make it more prominent as new users often don't see it.
My plan was to put it in the menu bar, on the right of the menu items. However many people voiced their concern about portability to linux/macos.
After thinking about it, instead of adding a combobox to the menubar, we could make a menu item which would have a special style to match the style of our current workbench selector.
So the question is: can we customize the style of a single menu item? More specifically: add an icon, change font size/color, background color. Also change the menu item text.
So that in the end it actually acts as a combobox.See below picture.
Thanks !
Edit: I might have find some information about it here : https://forum.qt.io/topic/121897/how-to-apply-css-styles-only-to-certain-items-in-menu-and-tool-bar/4
Though if you have additional input don't hesitate :) -
Doing this :
QMenu* wbMenu = menuBar->addMenu("Workbench"); wbMenu->setStyleSheet(QString::fromLatin1("QMenu { color: white; background-color: blue; font: bold 18px }")); wbMenu->addActions(_group->actions()); menuBar->addMenu(wbMenu);
Gives the style to all the sub-items (in my case QActions). But the menu "Workbench" doesn't change.
I'm not sure how to use custom properties and stylesheets. I tried the following but it doesn't work and feels wrong.
QMenuBar* menuBar = getMainWindow()->menuBar(); menuBar->setStyleSheet(QString::fromLatin1("QMenu[wbSelector=true] { color: white; background-color: blue; font: bold 18px }")); QMenu* wbMenu = menuBar->addMenu("Workbench"); wbMenu->addActions(_group->actions()); wbMenu->style()->unpolish(wbMenu); wbMenu->style()->polish(wbMenu); menuBar->addMenu(wbMenu);
The stylesheet is applied to the QMenuBar, but the property cannot be added to the menuBar, so I'm trying to the menu item I want to change.