Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set text color in QLineEdit when background image is set for QlineEdit

Tags:

c++

qt

I have a QLineEdit and i have set an image to QStackedWidget. Now i want to change the font color of Texts which is in 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. But its not work for me.

like image 1000
Suresh Avatar asked Jan 24 '14 08:01

Suresh


2 Answers

This worked for me :

    QPalette *palette = new QPalette();
palette->setColor(QPalette::Text,Qt::red);
line->setPalette(*palette);
like image 52
Metoo Avatar answered Sep 21 '22 01:09

Metoo


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");
like image 33
Mathijs Avatar answered Sep 19 '22 01:09

Mathijs