[PyQt] Properties in PyQt5

Glenn Ramsey gr at componic.co.nz
Wed Sep 24 05:03:30 BST 2014


I have a dialog that has been created in Qt Designer and I would like to
be able to set a red border on a QLineEdit based on its contents (or lack thereof).

Below is what I have tried, based on the PyQt4 version in Mark Summerfield's
book "Rapid GUI programming with Python and Qt", but it doesn't work.

What have I done wrong here?


ui = Ui_MyDialog()


invalidStyle = """
QLineEdit[invalid="true"] {
    border: 2px solid red;


print ui.myLineEdit.property("invalid")
# prints None

ui.myLineEdit.setProperty("invalid", QVariant(True))

print ui.myLineEdit.property("invalid")
# prints True

# expected my QLineEdit to have a red border now, but it doesn't change its

More information about the PyQt mailing list