munna
14th January 2009, 13:07
Hi!
When I set palette on QMenu it doesn't seem to be working. The following is the code
Selector_Menu::Selector_Menu(QWidget *parent) : QMenu(parent)
{
setMinimumWidth(52);
setAutoFillBackground(true);
QPalette p = palette();
p.setColor(QPalette::Window, QColor(5, 5, 5));
setPalette(p);
}
I add actions to this menu from the function where I create this object. Something like this
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
RMS_Output_Assignment_Selector_Menu::RMS_Output_As signment_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
When I set palette on QMenu it doesn't seem to be working. The following is the code
Selector_Menu::Selector_Menu(QWidget *parent) : QMenu(parent)
{
setMinimumWidth(52);
setAutoFillBackground(true);
QPalette p = palette();
p.setColor(QPalette::Window, QColor(5, 5, 5));
setPalette(p);
}
I add actions to this menu from the function where I create this object. Something like this
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
RMS_Output_Assignment_Selector_Menu::RMS_Output_As signment_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