PyQt and QtDesigner
Question: I am trying to implement a LED in PyQt named disLDR1 by trying to change the
background color. I am trying to use QPalette to change the BackgroundRole.
But what is the equivalent of Qt::red?

Is this the correct way to set the background color or is there any other way?

    
    
    #!/usr/bin/python -d
    
    import sys
    from PyQt4 import QtCore, QtGui
    from main import Ui_Form
    from PyQt4.QtGui import QPalette
    
    class Top(QtGui.QMainWindow):
        def __init__(self, parent = None):
            QtGui.QWidget.__init__(self, parent)
            self.ui = Ui_Form()
            self.ui.setupUi(self)
            for i in 1, 10:
                self.setOff()
                self.setOn()
        def setOff(self):
            self.pal = QPalette(self.ui.disLDR1.palette())
            self.pal.setColor(self.ui.disLDR1.backgroundRole(), <<<RED COLOR>>>)
            self.ui.disLDR1.setPalette(pal)
        def setOn(self):
            self.pal = QPalette(self.ui.disLDR1.palette())
            self.pal.setColor(self.ui.disLDR1.backgroundRole(), <<<GREEN COLOR>>>)
            self.ui.disLDR1.setPalette(pal)
    
    
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        myapp = Top()
        myapp.show()
        sys.exit(app.exec_())
    

EDIT: I have been trying to take help from [In Qt, how do I set the background
color of a widget like combobox or double spin
box?](http://stackoverflow.com/questions/177778/in-qt-how-do-i-set-the-
background-color-of-a-widget-like-combobox-or-double-spin) but don't know what
to substitute for QT::red


Answer: You can find the list of predefined Qt color objects at [this
link](http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qt.html#GlobalColor-
enum). In this case you would just need to use `QtCore.Qt.red` and
`QtCore.Qt.blue`. You could also use the
[`QColor`](http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qcolor.html)
class to generate arbitrary colors.

It's a matter of preference, but I personally think the easiest and most
powerful way to go would be to use a [style
sheet](http://doc.qt.nokia.com/latest/stylesheet.html).

