Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the Color and Font of QString or QLineEdit

How can I change the color and font of QLineEdit?

Here is my code:

self.lineEdit = QtGui.QLineEdit(widget)
self.lineEdit.setText("enter keywords here") #I want this to be in italics and in brown color

The setText line from Documentation says the text inside is of QString how can I change it's font and color?

like image 418
learncode Avatar asked Dec 29 '16 21:12

learncode


1 Answers

For the Color use QPallete, then use {your palette}.setColor(QtGui.QPalette.Text, {your QColor}), and the font use QFont

My Solution:

from PyQt4 import QtGui

from PyQt4 import QtCore


if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    w = QtGui.QLineEdit()
    palette = QtGui.QPalette()
    palette.setColor(QtGui.QPalette.Text, QtCore.Qt.red)
    w.setPalette(palette)
    font = QtGui.QFont("Times", 15, QtGui.QFont.Bold)
    w.setFont(font)
    w.show()
    sys.exit(app.exec_())

enter image description here

like image 181
eyllanesc Avatar answered Sep 29 '22 02:09

eyllanesc