简体   繁体   中英

Changing the Color of QLineEdit's Placeholder Text

I am writing an application in Qt 4.8 and taking advantage of styling through CSS. When styling QLineEdit there are properties such as selection-background-color , is there a property that will allow me to change the color of placeholder text?

If not, are there any other methods of changing it?

The color of the placeholder is the color of the text with alpha set to 50%. At least in 4.7 this was hardcoded and could thus not be changed with style.

As the decision is implemented in QLineEdit::paintEvent you could override paintEvent in a derived class and change the color to whatever suits you fine.

But why would you want a different color? If you change it to red or something like that, you might irritate a user who cannot distinguish a placeholder from "real" text anymore.

也许可以将调色板更改连接到信号textChanged():当行编辑为空时,更改文本颜色。

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