1

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.

uliwitness
  • 8,532
  • 36
  • 58

2 Answers2

1

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.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • No call to QApplication::setStyleSheet() in the app. I even commented out all setStyleSheet() and setStyle calls I could find and the main window is still black, as are its contextual menus. – uliwitness Mar 31 '17 at 17:17
  • If the window has been drawn in the designer, check the stylesheet property there (in the .ui file). – Matteo Italia Mar 31 '17 at 17:39
1

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
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • I deleted all styleSheets from the .ui files and all setStyle calls from the code... Still weird black context menus in the black window content view :( – uliwitness Apr 07 '17 at 21:08