You don't need a global list of styles, because that is already available from QStyleFactory.keys.
What you need to do is load those keys into the combo-box, set the combo-box index to the current style, and then connect the combo-box activated
signal to a handler so that the style can be changed.
Something like this should work:
import sys
from PyQt4 import QtCore, QtGui
class AppWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(AppWidget, self).__init__(parent)
horizontalLayout = QtGui.QHBoxLayout()
self.styleLabel = QtGui.QLabel("Set Style:")
self.styleComboBox = QtGui.QComboBox()
# add styles from QStyleFactory
self.styleComboBox.addItems(QtGui.QStyleFactory.keys())
# find current style
index = self.styleComboBox.findText(
QtGui.qApp.style().objectName(),
QtCore.Qt.MatchFixedString)
# set current style
self.styleComboBox.setCurrentIndex(index)
# set style change handler
self.styleComboBox.activated[str].connect(self.handleStyleChanged)
horizontalLayout.addWidget(self.styleLabel)
horizontalLayout.addWidget(self.styleComboBox)
self.setLayout(horizontalLayout)
# handler for changing style
def handleStyleChanged(self, style):
QtGui.qApp.setStyle(style)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
widgetApp = AppWidget()
widgetApp.show()
sys.exit(app.exec_())