简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM