PyQT LineEdit Border Color
Asked Answered
M

1

8

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!

Mood answered 17/1, 2014 at 18:58 Comment(0)
M
19

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
Malversation answered 17/1, 2014 at 19:4 Comment(1)
Works great! Thanks! Another question if you wouldn't mind. How do I reset the border from: 1px solid red; to default?Mood

© 2022 - 2024 — McMap. All rights reserved.