Application wide stylesheet with different styles for menu and context menu?
-
I'm using one stylesheet for my application, actually one for several applications, and naturally when I define styles for QMenu they are used for the menu items of the menubar as well as for the context menues.
Is there an easy way to define different styles for menu items and context menues?
-
-
Thanks for the hint, but the issue is not with the entries of the QMenubar (so to say menu headers) but with the QMenu items ( menu entries) . If I design a menubar I get the styling fot the headers with QMenubar but the entries are styled the same as any other QMenu.
-
It's just copy paste from the given examples - wanted to check out what I can achieve.
/* Menubar - does all the styling of the menubar*/
QMenuBar {
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 lightgray, stop:1 darkgray);
}QMenuBar::item {
spacing: 3px; /* spacing between menu bar items */
padding: 1px 4px;
background: transparent;
border-radius: 4px;
}QMenuBar::item:selected { /* when selected using mouse or keyboard */
background: #a8a8a8;
}QMenuBar::item:pressed {
background: #888888;
}/* Menus - context items and menubar items /
QMenu {
background-color: rgb(149, 166, 174); / grau */
}QMenu::item {
background-color: transparent;
}QMenu::item:selected {
background-color: rgb(163, 3, 47); /* rot */
} -
You can define an accessibleName for your objects and distribute different StyleSheets.
either via the designer or QWidget::setAccessibleName(const QString &name);e.g.
QPushButton{ background-color: blue; } QPushButton[accessibleName="SpecialButton1"] { background-color: red; }