Suresh
Suresh

Reputation: 765

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. 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.

Upvotes: 8

Views: 16770

Answers (2)

Metoo
Metoo

Reputation: 400

This worked for me :

    QPalette *palette = new QPalette();
palette->setColor(QPalette::Text,Qt::red);
line->setPalette(*palette);

Upvotes: 19

Mathijs
Mathijs

Reputation: 357

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");

Upvotes: 10

Related Questions