[英]How to set text color in QLineEdit when background image is set for QlineEdit
I have a QLineEdit
and i have set an image to QStackedWidget
. 我有一个QLineEdit
,我已经将图像设置为QStackedWidget
。 Now i want to change the font color of Texts which is in QLineEdit
. 现在我想更改QLineEdit
本的字体颜色。 How to do it? 怎么做?
QLineEdit *line1 = new QLineEdit("Hello");
QStackedWidget *stack1 = new QStackedWidget();
stack1->addWidget(line1);
stack1->setStyleSheet("background-image: url(black.gif);");
I tried writing foreground-color
and foreground
in setStyleSheet.
我尝试在setStyleSheet.
编写foreground-color
和foreground
setStyleSheet.
But its not work for me. 但它不适合我。
This worked for me : 这对我有用:
QPalette *palette = new QPalette();
palette->setColor(QPalette::Text,Qt::red);
line->setPalette(*palette);
Normally, this can be achieved by setting the color stylesheet property, so no foreground-color or something like that. 通常,这可以通过设置颜色样式表属性来实现,因此没有前景色或类似的东西。 So this should do it: 所以这应该这样做:
QLineEdit *line1 = new QLineEdit("Hello");
QStackedWidget *stack1 = new QStackedWidget();
stack1->addWidget(line1);
stack1->setStyleSheet("background-image: url(black.gif); color: #FFFFFF");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.