[PyQt] Properties in PyQt5

Vincent Vande Vyvre vincent.vande.vyvre at telenet.be
Wed Sep 24 05:32:02 BST 2014


Le 24/09/2014 06:03, Glenn Ramsey a écrit :
> Hi,
>
> 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?
>
> Glenn
>
> ui = Ui_MyDialog()
> ui.setupUi(self)
>
> ...
>
> invalidStyle = """
> QLineEdit[invalid="true"] {
>      border: 2px solid red;
> }
> """

true or True ?
>
> ui.myLineEdit.setStyleSheet(invalidStyle)
>
> 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
> appearance.
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Vincent


More information about the PyQt mailing list