What's the correct way to apply styles for a QMenu object?
I'm trying this:
QMenu contextMenu(tr("Context menu"), this);
contextMenu.addAction(new QAction(tr("Hello"), this));
contextMenu.setStyleSheet("*:hover { color:#FFF; } *:!hover { color:#aaa; }");
I'm trying to set different text colors for when the mouse is over the menu option and when the mouse isn't over the option. But it's not working.
In case of QMenu
styling use QMenu::item:selected
Here is an example
QMenu::item{
background-color: rgb(0, 170, 0);
color: rgb(255, 255, 255);
}
QMenu::item:selected{
background-color: rgb(0, 85, 127);
color: rgb(255, 255, 255);
}
In your case
QString menuStyle(
"QMenu::item{"
"background-color: rgb(0, 170, 0);"
"color: rgb(255, 255, 255);"
"}"
"QMenu::item:selected{"
"background-color: rgb(0, 85, 127);"
"color: rgb(255, 255, 255);"
"}"
);
this->setStyleSheet(menuStyle);
Refer the Qt Style Sheets example for more options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With