The styleSheet module contains the StyleSheet class which provides the ability to more easily create a string for setting the style sheet of a QWidget.
The StyleSheet class provides a wrapper for PyQt4.QtGui.QWidget style sheet strings. StyleSheets can be easily created an exported into a string that is properly formatted for setting the style sheet of a PyQt4.QtGui.QWidget.
Example:
from PyQt4.QtGui import QApplication, QWidget
from pyamp.ui.qt import StyleSheet
# Create the widget, and set its name
app = QApplication([])
widget = QWidget()
widget.setObjectName("ObjectName")
# Create a simple style sheet
style = StyleSheet(border="2px solid black")
normal = "border: 2px solid black"
# These calls are identical
widget.setStyleSheet(str(style))
widget.setStyleSheet(normal)
# Create another style sheet, notice that underscores in the
# StylSheet parameter names are converted to dashes in the
# style sheet string
style = StyleSheet(background_color="red", color="blue",
font_weight="bold")
normal = "background-color: red; color: blue; font-weight: bold"
# These calls are identical
widget.setStyleSheet(str(style))
widget.setStyleSheet(normal)
# You can also specify a specific CSS selector string, which can be
# either a specific string, or a widget. If given a widget, the
# selector will be created using the object's class name (e.g.,
# QWidget) and will append an ID selector with the object's name (if
# and only if the widget is named).
style1 = StyleSheet(widget="QWidget#ObjectName",
border="1px solid red", margin_top="10")
style2 = StyleSheet(widget, border="1px solid red", margin_top="10")
normal = "QWidget#ObjectName { border: 1px solid red; margin-top: 10;"
# These calls are identical
widget.setStyleSheet(str(style1))
widget.setStyleSheet(str(style2))
widget.setStyleSheet(normal)
string, or an actual widget object
kwargs – The keyword arguments