Reputation: 8773
I've inherited a Qt project that had themed right-click menus (which look really weird on macOS). I removed the setStyleSheet() call from the QMenu, yet it still highlights only the text instead of the item's background and uses weird font sizes.
Is there any other place in a Qt app where someone could have set colors that the menu would somehow inherit?
The menu is shown via exec(), and the QMenu and QActions are created with a QWidget as their parent, in case that helps.
Upvotes: 1
Views: 142
Reputation: 98425
The styles are inheritable. There can be a global stylesheet, or a stylesheet on any of the widgets that are parents of the menu being shown. You'll need to inspect them all and remove menu styles.
You could limit the applicability of the menu styles by using a dynamic property to describe whether the style should apply or not:
QMenu[styled="true"] { ... }
Then, on the platforms where the menus are styled, apply the property:
void styleMenu(QMenu * menu) {
#ifndef Q_OS_MACOS
menu->setProperty("styled", true);
#endif
}
...
styleMenu(menu); // no-op on OS X
Upvotes: 1
Reputation: 126777
Probably it has been set globally; look for a call to QApplication::setStyleSheet, and for a QMenu
selector inside that global stylesheet. It may also be set into a stylesheet of a parent widget.
In general, if I were you I'd grep the project for stylesheets that contain a QMenu
selector.
Upvotes: 1