PDA

View Full Version : QPalette problem/bug in QMenu with custom style



warchild
23rd October 2012, 06:52
Hello,

1. I have created a custom style derived from QWindowsStyle.
2. Implemented QStyle::polish(QPalette&).
3. In QStyle::drawControl I have overridden painting of CE_MenuItem.

The result is that basic background on windows and buttons conform with the changed palette colors (QPalette::Window, QPalette::Base, QPalette::Button, etc).
But the palette used in QStyleOptionMenuItem when drawing CE_MenuItem element is only partly updated with the new palette specified in QStyle::polish(QPalette&).
Particularly QPalette::Button color that I'm using to paint the CE_MenuItem background is still the same as used in the base class palette. I can solve this by using hard-coded colors but in that case I'm missing the point with QPalette.

I consider this a bug, or is there something special with QMenu widget that I'm not aware of?
QMenu::initStyleOption only shows something like option->palette = palette(), which probably means QWidget::palette() is called, and that should result in, according to my opinion, the correct palette should be returned.

Using Qt 4.8.3.