python QLineEdit 文本颜色 [英] python QLineEdit Text Color
本文介绍了python QLineEdit 文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个演示应用程序来展示如何更改字体颜色.
I am trying to create a demonstration app to show how to change font colors.
我可以在 QLabel 和 QTextEdit 中完成
I can do it in QLabel and QTextEdit
我发现无法更改 QLineEdit 的前景色.
I have found no way to change the foreground text color for a QLineEdit.
我尝试过的唯一不会抛出错误的是:
The only thing I've tried that does not throw an error is:
color = QColorDialog.getColor(defaultHost.textColor(), pWidget, 'Get Text Color')
myPalette.setColor(myPalette.WindowText, QColor(color))
但是,文本颜色仍然是黑色...
But, the text color remains black...
是否可以这样做?
推荐答案
你可以通过 设置对象的样式表:
self.my_line_edit = QtGui.QLineEdit()
self.my_line_edit.setStyleSheet("color: red;")
# or
self.my_line_edit.setStyleSheet("color: rgb(255, 0, 0);")
# or
self.my_line_edit.setStyleSheet("""
QLabel {
color: red;
}
""")
这篇关于python QLineEdit 文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文