2 Attachment(s)
Weird QMenu behavior on Mac
Hi!
When I set palette on QMenu it doesn't seem to be working. The following is the code
Code:
Selector_Menu
::Selector_Menu(QWidget *parent
) : QMenu(parent
){
setMinimumWidth(52);
setAutoFillBackground(true);
setPalette(p);
}
I add actions to this menu from the function where I create this object. Something like this
Code:
menu = new Selector_Menu(this);
currentAction = menu->addAction("A");
menu->addSeparator();
menu->addAction("B");
menu->addSeparator();
menu->addAction("C");
Output looks like the Picture1 attached
When I use stylesheets I get the output which looks like the Picture2 attached
Code:
RMS_Output_Assignment_Selector_Menu
::RMS_Output_Assignment_Selector_Menu(QWidget *parent
) : QMenu(parent
){
setMinimumWidth(52);
setAutoFillBackground(true);
QString menu_ss
= "QMenu { color: white; background-color: black; }" + QString("QMenu::item:selected { color: grey; background-color: black; }");
setStyleSheet(menu_ss);
}
Any idea on why is the background not being set properly in the menu. I am using Qt 4.3.1
Thanks a lot for the help
Re: Weird QMenu behavior on Mac
Hey Munna!
I've already implemented applications both StyleSheet and Palette based for Mac OS X.
The truth is: they're both (speacially the Palette approach) buggy on (specially, again) Mac.
Up to Qt 4.4.3, some QWidgets properties (including palette) propagation has erronous behaviours. This issue seem to be addressed on Qt 4.5. But, as a workaround, you could implement some function like this:
Code:
{
widget->setPalette(palette);
foreach
(QObject *object, widget
->children
()) if (QWidget *child
= (object
->isWidgetType
() ? dynamic_cast<QWidget
*>
(object
) : NULL)) applyPaletteTo(palette, child);
}
and call
Code:
applyPaletteTo(yourCustomPalette, yourCustomMenu);
Note that, for this to have effect, it must be done AFTER the widget construction (not the constructor, but the whole 'addSomething' stuff).
Now for your StyleSheet problem, try the following:
Code:
QString menu_ss
= "QMenu { color: white; background-color: black; }" "QMenu::item { background-color: black; }"
"QMenu::item:selected { color: grey; background-color: black; }";
Best regards,
tinsukE