I want to add colorless icons to menu items. To look reasonably, the icons should have the same color as the text used in the menu. It works everywhere except Ubuntu. The problem is that the default Ubuntu Unity theme uses different colors for the main menu and for other text (e.g. popup menus) in the application. I need the color specifically used by the main menu.
QApplication.palette().color(QPalette.Text) returns the dark gray color used by text in the application. It's almost invisible on the dark gray menu background.
I tried the palette() method on a QMenu descendant, but it returns the same value as QApplication.palette().
It turns out QMainWindow.menuBar().palette() has colors matching the Unity menu on top of the screen (I just learned it's called appmenu). That makes it possible to use the same color as the menu text.
But there is a problem. The version of the icon for the QtIcon.Active mode is not used for the active menu item. That can be seen in the high contrast mode. The text color changes, but the icon color doesn't. The icon "disappears" when the menu item is selected. That's not good enough for a polished program.
I tried many workarounds, such as adding extra pixmaps to the icon with QIcon.addPixmap(). Nothing works. The appmenu operates in a separate process and doesn't want to our "Active" icon. So I'm going to draw real icons that look good on any reasonable background and don't need to change color with the widget.
Too bad. I expected that the QIcon mode and state were made specifically for such tasks.
PyQt: How to find menu text color in that works with Ubuntu Unity?