qstylizer.style¶
-
class
qstylizer.style.
StyleRule
(name=None, value=None, parent=None)[source]¶ StyleRule Object.
A dictionary containing nested Styles and property:value pairs.
Example structure:
<ClassRule name="QCheckBox" dict={ "color": <PropRule name="color" value="red" />, "background-color": <PropRule name="background-color" value="black" />, "indicator": <SubControlRule name="indicator" dict={ "border": <PropRule name="border" value="1px solid green" />, "hover": <PseudoStateRule name="hover" dict={ "background-color": <PropRule name="background-color" value="green" />, "border": <PropRule name="border value="0px transparent black" /> } /> } /> } />
Output format:
<selector> { <property>: <value>; <property>: <value>; ... }
Stylesheet output:
QCheckBox { color: red; background-color: black; } QCheckBox::indicator { border: 1px solid green; } QCheckBox::indicator:hover { background-color: green; border: 0px transparent black; }
-
classmethod
split_selector
(selector)[source]¶ Split the selector based on the _split_regex.
Return a list of each component. Example:
name = "QObject::subcontrol:pseudostate" return value = ["QObject", "::subcontrol", ":pseudostate"]
- Parameters
name – String name
-
__init__
(name=None, value=None, parent=None)[source]¶ Initialize the StyleRule dictionary.
Note
All public variables will be put into ordered dictionary.
- Parameters
name – The name of the StyleRule
value – The property value
parent – The parent StyleRule
-
find_or_create_child_rule
(name)[source]¶ Find or create a child rule from a string key.
If the key rule already exists, return the rule. If there is a comma in requested key, return a StyleRuleList object. Otherwise create rules from the style rule names in the key and return the top level rule or property.
- Parameters
name – The dictionary key
-
find_child_rule
(key)[source]¶ Find rule from key.
Return the sanitized key’s hash value in the ordered dict.
-
create_child_rule_list
(name)[source]¶ Create a StyleRuleList object and add it to ordered dict.
- Parameters
name – String name
-
create_child_rules
(selector)[source]¶ Create child rules from selector string.
Split the selector into individual components based on the _split_regex and recursively build the StyleRule hierarchy looping through the components.
If selector is “QClass::subcontrol:pseudostate”, curr_name is “QClass” and remaining is “::subcontrol:pseudostate”
- Parameters
name – String to split
-
create_child_rule
(name)[source]¶ Create child rule from name.
Determine subclass from name, create an instance of the subclass, then add it to ordered dict.
- Parameters
name – String name
-
property
selector
¶ Get the selector.
Example:
Object::subcontrol:pseudostate
-
property
name
¶ Return the name of the StyleRule (eg. “QCheckBox”).
Strip off the scope operator if it exists in name.
-
property
parent
¶
-
property
scope_operator
¶ Get the scope operator.
The scope operator is the “::” or “:” that is printed in front of the name of the StyleRule in the selector.
Subclasses are expected to define the scope operator or else it will try to guess it based on its position in the hierarchy.
-
is_leaf
()[source]¶ Determine if StyleRule is a leaf.
StyleRule is a leaf its child rules dictionary contains only PropRules.
-
is_top_level
()[source]¶ Determine if StyleRule is top level.
StyleRule is top level if its parent is of the StyleSheet class.
-
toString
(*args, **kwargs)[source]¶ Convert to a single string in css format.
Use camelcase for function name to match PyQt/PySide.
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.[source]¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
setValues
(*args, **kwargs)[source]¶ Set property values in the style rule.
Use camelcase for function name to match PyQt/PySide.
-
property
value
¶
-
classmethod
-
class
qstylizer.style.
StyleSheet
(name=None, value=None, parent=None)[source]¶ The StyleSheet definition.
Contains descriptors for all class and property options.
-
is_global_scope
()[source]¶ Determine if stylesheet is global scope.
A StyleSheet is global scope if it has no rules. Resulting string should contain no brackets.
background-color: red; border: none;
-
property
name
¶ Return the name of the StyleSheet.
-
-
class
qstylizer.style.
ClassRule
(name=None, value=None, parent=None)[source]¶ The ClassRule definition.
Example class rule name: “QCheckBox”. Contains descriptors for all subcontrols and pseudostates.
-
class
qstylizer.style.
ObjectRule
(name=None, value=None, parent=None)[source]¶ The ObjectRule definition.
Example object rule name: “#objectName”. Inherits from ClassRule. Only difference is “#” is the scope operator.
-
property
scope_operator
¶ Get the scope operator.
The scope operator is the “::” or “:” that is printed in front of the name of the StyleRule in the selector.
Subclasses are expected to define the scope operator or else it will try to guess it based on its position in the hierarchy.
-
property
-
class
qstylizer.style.
ChildClassRule
(name=None, value=None, parent=None)[source]¶ The ChildClassRule definition.
Example object rule name: ” QFrame”. Inherits from ClassRule.
QWidget QFrame { property: value }
-
property
scope_operator
¶ Get the scope operator.
The scope operator is the “::” or “:” that is printed in front of the name of the StyleRule in the selector.
Subclasses are expected to define the scope operator or else it will try to guess it based on its position in the hierarchy.
-
property
-
class
qstylizer.style.
ObjectPropRule
(name=None, value=None, parent=None)[source]¶ The ObjectPropRule definition.
Example object property rule name: “[echoMode=”2”]”.
-
property
scope_operator
¶ Get the scope operator.
The scope operator is the “::” or “:” that is printed in front of the name of the StyleRule in the selector.
Subclasses are expected to define the scope operator or else it will try to guess it based on its position in the hierarchy.
-
property
-
class
qstylizer.style.
StyleRuleList
(name=None, value=None, parent=None)[source]¶ The StyleRuleList definition.
Example rule list name: “QCheckBox, QComboBox”.
-
property
scope_operator
¶ Get the scope operator.
The scope operator is the “::” or “:” that is printed in front of the name of the StyleRule in the selector.
Subclasses are expected to define the scope operator or else it will try to guess it based on its position in the hierarchy.
-
property
name
¶ Return the name with no spaces.
-
property
-
class
qstylizer.style.
SubControlRule
(name=None, value=None, parent=None)[source]¶ The SubControlRule definition.
Example subcontrol name: “::indicator”.
-
property
scope_operator
¶ Get the scope operator.
The scope operator is the “::” or “:” that is printed in front of the name of the StyleRule in the selector.
Subclasses are expected to define the scope operator or else it will try to guess it based on its position in the hierarchy.
-
property
-
class
qstylizer.style.
PseudoStateRule
(name=None, value=None, parent=None)[source]¶ The PseudoStateRule definition.
Example pseudostate name: “:hover”.
-
property
scope_operator
¶ Get the scope operator.
The scope operator is the “::” or “:” that is printed in front of the name of the StyleRule in the selector.
Subclasses are expected to define the scope operator or else it will try to guess it based on its position in the hierarchy.
-
property
-
class
qstylizer.style.
PseudoPropRule
(name=None, value=None, parent=None)[source]¶ The PseudoPropRule definition.
The PseudoPropRule covers PseudoStates and properties that have the same name like “top”, “bottom”, “left”, and “right”.
It is basically a PseudoStateRule that also stores a property value. In the following example, top is the PseudoPropRule.
>>> css.QWidget.tab.top = "0" >>> css.QWidget.tab.top.color = "green" >>> print(css.toString()) QWidget::tab { top: 0; } QWidget::tab:top { color: green; }