In PySide, I am trying to change the overall style of a simple GUI window (a QLabel object), as outlined at the PySide documentation:
http://srinikom.github.io/pyside-docs/PySide/QtGui/QStyle.html#detailed-description
That is, as described at that link, I want to use setStyle
to change the overall GUI format to one of the pre-defined GUI styles (e.g., from Windows
to Cleanlooks
). (As I note below, this goal is different from tweaking colors and such using setStyleSheet
, which I already know how to do).
To get started, I first checked what style types I have available:
print QtGui.QStyleFactory.keys()
This revealed many available styles, including 'Cleanlooks'.
Second, based on documentation from three sources (PySide, ZetCode, and Nullege), I tried to change my QLabel style to 'Cleanlooks':
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
Unfortunately, this changed nothing. In fact, nothing I enter has changed a single pixel in my Hello World widget. Not sure if relevant, but when I print the output of the previous line of code, I always get None
. Full example code is below the fold.
I am in Windows 7, Python 2.7 running within iPython. Based on replies, this seems to be an issue with PyQt4 in Windows 7 too, not just PySide.
Just to be extra clear, I am not asking about how to use setStyleSheets
to tweak my widget. This has been addressed decently already:
Styling with classes in Pyside + Python
Example of code I tried (other permutations I tried are shown in comments):
# coding: utf-8
import sys
from PySide import QtGui
class HelloWorldApp(QtGui.QLabel):
def __init__(self):
QtGui.QLabel.__init__(self, "Hello, world!")
self.initUI()
def initUI(self):
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
self.show()
def main():
#QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks')) #crashes program
qt_app=QtGui.QApplication(sys.argv)
#QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks')) #does nothing
exHell=HelloWorldApp()
sys.exit(qt_app.exec_())
if __name__=="__main__":
main()