Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQT LineEdit Border Color

To bring the user's attention to the text field with an error (or if it is not filled) I colorize this QLineEdit) using:

red = "QWidget { background-color:#8B0000;}"
my_cool_QLineEdit.setStyleSheet(red)

That makes an entire background of this QLineEdit red. While the message is definitely sent that doesn't look too tasteful. Instead of QLineEdit's background I wonder if it is possible to turn only its borders red. What method to use? Many thanks in advance!

like image 610
alphanumeric Avatar asked Jan 17 '14 18:01

alphanumeric


1 Answers

Try this:

from PyQt4 import QtGui

app = QtGui.QApplication([])

w = QtGui.QWidget()
le = QtGui.QLineEdit(w)
lay = QtGui.QHBoxLayout()
w.setLayout(lay)
lay.addWidget(le)
le.setStyleSheet("border: 1px solid red;")
w.show()
app.exec_()

If you want to save the previous color do this:

ss = le.styleSheet() #original saved
le.setStyleSheet("border: 1px solid red;") #changed
le.setStyleSheet(ss) #back to original
like image 146
Alvaro Fuentes Avatar answered Oct 08 '22 08:10

Alvaro Fuentes