问题描述
正如你在下面的截图中看到的,所选项目的字体颜色是白色作为它的背景色,这导致我们看不到项目文本,这个问题存在于我的应用程序中的所有 QLineEdits 中,所以我只想将所有 QLineEdits 的上下文菜单的所选项目的字体颜色设置为黑色,是否有任何代码较少的快速方法来做到这一点?
解决方法
只需为您的应用程序设置 css
int main(int argc,char *argv[])
{
QApplication a(argc,argv);
a.setStyleSheet("QLineEdit QMenu::item {color: rgb(0,255);}");
MainWindow w;
w.show();
return a.exec();
}
如果您只想为选定(活动)项目设置字体颜色,则应更正此代码
a.setStyleSheet("QLineEdit QMenu::item {\ncolor: rgb(0,255);\n} QLineEdit QMenu::item::selected{ color: rgb(255,0)}");