Qt APP样式表问题

Problem in stylesheet of Qt APP

本文关键字:问题 样式 APP Qt      更新时间:2023-10-16

在我的应用程序中,我有一个部分是顶部小部件,顶部小部件的颜色是灰色的,我已经把几个小部件放在顶部小部件上,如QComboBox, QLineEdit和2 QButton,但我有一个问题,当我右键单击QLineEdit,正如你在下图中看到的,窗口默认上下文的颜色是灰色的,或者当我打开QComboBox的背景颜色是灰色的。我将这两个小部件的背景色设置为白色,但不工作。那么,我怎么才能解决这个问题呢?

更好理解的示例:

http://0000.4.img98.net/out.php/i52512_problem.png

请帮帮我

样式表传播到所有子部件,因此您必须通过使用正确的选择器来限制它们的范围。因为上下文菜单是QLineEdit的子菜单,所以它也会受到影响。

// What you have probably done:
myLineEdit->setStyleSheet("background-color: gray");
// What you should have done:
myLineEdit->setStyleSheet("QLineEdit { background-color: gray }");      
// What you should do if there might be child widgets of the same type 
// but for which you don't want the style to apply:
myLineEdit->setObjectName("myLineEdit");
myLineEdit->setStyleSheet("QLineEdit#myLineEdit { background-color: gray }");