python QLineEdit Text Color

后端 未结 4 531
野性不改
野性不改 2021-01-04 09:17

I am trying to create a demonstration app to show how to change font colors.

I can do it in QLabel and QTextEdit

I have found no way to change the foreground

4条回答
  •  佛祖请我去吃肉
    2021-01-04 09:32

    You can do it by setting the object's style sheet:

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

提交回复
热议问题