python QLineEdit Text Color

后端 未结 4 522
野性不改
野性不改 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:52

    this is how I do it not using css

    Palette= QtGui.QPalette()
    Palette.setColor(QtGui.QPalette.Text, QtCore.Qt.red)
    self.lineEdit.setPalette(Palette)
    

    QLineEdit has a method initStyleOption and initStyleOption inherits QStyleOption, and then QStyleOption has a Method QPalette. Now you can take advatage of using QPalette methods.

    you can visit this link for reference http://pyqt.sourceforge.net/Docs/PyQt4/qlineedit.html

提交回复
热议问题