I want to make a green button. I did this:
Do not use stylesheets if you want completely consistent results on all platforms. The reasons for this are explained in this answer.
If you only need to set the background colour, use the widget's palette:
palette = self.detectButton.palette() palette.setColor(QtGui.QPalette.Button, QtGui.QColor('#00ff00')) self.detectButton.setPalette(palette)
It seems unlikely that there's a systematic way to generate colours that work equally well on all platforms. Probably the best you can do is try to tweak one of the system colours that are accessible via the palette color roles.
It seems I was wrong to assume that the palette method is a reliable cross-platform solution. The Qt docs for
QPalette has the following:
Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the OS X styles.
So it seems there isn't even a completely consistent, cross-platform way to do something as simple as changing the background colour.