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
Qt4.8.5 QLabel设置样式表忽略继承的字体_Qt_Stylesheet - Fatal编程技术网

Qt4.8.5 QLabel设置样式表忽略继承的字体

Qt4.8.5 QLabel设置样式表忽略继承的字体,qt,stylesheet,Qt,Stylesheet,我想通过setStylesheet设置一些样式属性,例如边框 label.setStylesheet("border: 1px solid white;"); 之后,我的标签有一个白色边框,但是在父窗口小部件(QDesigner)中设置的所有字体属性都被忽略 qDebug() << label->font().family(); qDebug() << label->font().rawName(); qDebug()字体().family(); qDeb

我想通过setStylesheet设置一些样式属性,例如边框

label.setStylesheet("border: 1px solid white;");
之后,我的标签有一个白色边框,但是在父窗口小部件(QDesigner)中设置的所有字体属性都被忽略

qDebug() << label->font().family();
qDebug() << label->font().rawName();
qDebug()字体().family();
qDebug()字体().rawName();
两者都打印正确的字体系列,但在调用setStylesheet函数后不应用此功能

颜色也是一样。如果我通过setStylesheet()设置了一些其他属性,则不会使用设计器中通过QPlatte设置的颜色


我不知道,但似乎我们不应该混合使用这两种技术,否则我在这里做错了什么。

不幸的是,在小部件的样式表中设置一个属性通常会导致需要设置所有样式属性,并破坏任何这些属性的继承。我无法在自己的环境中重现字体继承问题(您使用的是什么版本的Qt?),但下面的代码应该可以帮助您解决这个问题

//  Get the color of the label's parent (this).
QColor color = this->palette().windowText().color();
QString colorString = "rgb(" +
                      QString::number( color.red() ) + "," +
                      QString::number( color.green() ) + "," +
                      QString::number( color.blue() ) + ")";

//  Get the Font of the label's parent (this).
QFont font = this->font();

//  Set the Font and Color.
label->setFont( font );
label->setStyleSheet( "color: " + colorString + "; border: 1px solid white;" );
就我个人而言,我尝试将所有样式保存在特定表单对象样式的表单编辑器中,或者保存在顶层加载的样式表中,就像网页的CSS一样