为QMenu对象应用样式的正确方法是什么?
我正在尝试这个:
QMenu contextMenu(tr("Context menu"), this);
contextMenu.addAction(new QAction(tr("Hello"), this));
contextMenu.setStyleSheet("*:hover { color:#FFF; } *:!hover { color:#aaa; }");
Run Code Online (Sandbox Code Playgroud)
我正在尝试设置不同的文本颜色,当鼠标位于菜单选项上时以及鼠标未超出选项时.但它不起作用.
如果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);
}
Run Code Online (Sandbox Code Playgroud)在你的情况下
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);
Run Code Online (Sandbox Code Playgroud)有关更多选项,请参阅Qt样式表示例
| 归档时间: |
|
| 查看次数: |
4250 次 |
| 最近记录: |