Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt应用程序的样式表中存在问题_C++_Qt - Fatal编程技术网

C++ Qt应用程序的样式表中存在问题

C++ Qt应用程序的样式表中存在问题,c++,qt,C++,Qt,在我的应用程序中,我有一个部分是top widget,top widget的颜色是灰色的,我已经将severl widget放在了top widget上,比如QComboBox、QLineEdit和2 QButton,但是当我右键单击QLineEdit时出现了一个问题,如下图所示,窗口默认上下文的颜色是灰色的,或者,当我打开QComboBox时,背景颜色为灰色。我会将这两个小部件的背景色设置为白色,但不起作用。那么,我怎样才能解决这个问题呢 为了更好地理解,请选择以下示例: 请帮助我样式表会传

在我的应用程序中,我有一个部分是top widget,top widget的颜色是灰色的,我已经将severl widget放在了top widget上,比如QComboBox、QLineEdit和2 QButton,但是当我右键单击QLineEdit时出现了一个问题,如下图所示,窗口默认上下文的颜色是灰色的,或者,当我打开QComboBox时,背景颜色为灰色。我会将这两个小部件的背景色设置为白色,但不起作用。那么,我怎样才能解决这个问题呢

为了更好地理解,请选择以下示例:


请帮助我

样式表会传播到所有子窗口小部件,因此您必须使用正确的选择器来限制它们的范围。由于上下文菜单是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 }");

有关详细信息,请参见。

能否发布样式表?我假设您在样式表中设置灰色背景色的方式是将其自身应用到组合框的下拉列表中。但是如果我们看到你的样式表,我可以给你一个更好的答案。