QT:为QMenu对象设置样式表
为QMenu对象应用样式的正确方法是什么 我正在尝试这个:QT:为QMenu对象设置样式表,qt,Qt,为QMenu对象应用样式的正确方法是什么 我正在尝试这个: QMenu contextMenu(tr("Context menu"), this); contextMenu.addAction(new QAction(tr("Hello"), this)); contextMenu.setStyleSheet("*:hover { color:#FFF; } *:!hover { color:#aaa; }"); 我正在尝试为鼠标位于菜单选项上方和鼠标未位于菜单选项上方时设置不同的文本颜色。但
QMenu contextMenu(tr("Context menu"), this);
contextMenu.addAction(new QAction(tr("Hello"), this));
contextMenu.setStyleSheet("*:hover { color:#FFF; } *:!hover { color:#aaa; }");
我正在尝试为鼠标位于菜单选项上方和鼠标未位于菜单选项上方时设置不同的文本颜色。但它不起作用
QMenu
样式设置,请使用QMenu::item:selected
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);
}
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);