KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
StyleSheet< T > Class Template Reference

Template helper for building typed Qt stylesheet strings. More...

#include <stylesheet.h>

Public Member Functions

 StyleSheet ()
 Construct and capture the widget class name as the CSS selector.
 
void setProperty (StyleSheetProperty property, const QString &value)
 Set a stylesheet property to a string value.
 
void setProperty (StyleSheetProperty property, const QColor &value)
 Set a stylesheet property to a color value.
 
void setPropertyPixels (StyleSheetProperty property, int value)
 Set a stylesheet property to a pixel integer value.
 
void setGradient (const QString &gradient)
 Set the background to a gradient string (qradialgradient / qlineargradient).
 
void setRadialGradient (double cx, double cy, double radius, double fx, double fy, const QGradientStops &stops)
 Set the background to a radial gradient specified by its geometric parameters.
 
void setBorder (const QString &topLeft, const QString &bottomRight)
 Set all four border properties at once using the dome highlight/shadow convention.
 
void setBorder (int widthPx, const QColor &topLeft, const QColor &bottomRight)
 Set all four border properties using a pixel width and two colors.
 
void setPseudoState (StyleSheetPseudoState value)
 Set the pseudo-state selector (e.g., PS_Hover, PS_Checked).
 
void setSubControl (const QString &value)
 Set the sub-control selector string (e.g., "::handle").
 
QString toString () const
 Render all accumulated properties into a complete stylesheet rule.
 

Public Attributes

QString _typeName
 CSS selector class name (set from T::metaObject()->className()).
 
QMap< StyleSheetProperty, QString > _properties
 Accumulated property/value pairs for the stylesheet rule.
 
StyleSheetPseudoState _pseudoState = PS_Invalid
 Pseudo-state selector applied to the rule (PS_Invalid = none).
 
QString _subControl
 Sub-control selector string (empty = none).
 

Detailed Description

template<typename T>
class StyleSheet< T >

Template helper for building typed Qt stylesheet strings.

StyleSheet<T> is parameterized on a QWidget subclass. It captures the widget's class name at construction and accumulates property/value pairs that are rendered into a complete stylesheet rule by toString().

An optional pseudo-state (e.g., PS_Hover) and sub-control selector can narrow the rule to a specific widget state or part.

Template Parameters
TQWidget subclass whose class name is used as the selector

Definition at line 25 of file stylesheet.h.

Constructor & Destructor Documentation

◆ StyleSheet()

template<typename T >
StyleSheet< T >::StyleSheet ( )
inline

Construct and capture the widget class name as the CSS selector.

Definition at line 31 of file stylesheet.h.

Member Function Documentation

◆ setBorder() [1/2]

template<typename T >
void StyleSheet< T >::setBorder ( const QString &  topLeft,
const QString &  bottomRight 
)

Set all four border properties at once using the dome highlight/shadow convention.

Top and left edges receive topLeft (highlight); bottom and right receive bottomRight (shadow). This matches the standard glassy-dome button style used throughout the UI.

Parameters
topLeftCSS border value for the top and left edges
bottomRightCSS border value for the bottom and right edges

◆ setBorder() [2/2]

template<typename T >
void StyleSheet< T >::setBorder ( int  widthPx,
const QColor &  topLeft,
const QColor &  bottomRight 
)

Set all four border properties using a pixel width and two colors.

Generates "Npx solid rgba(r,g,b,a)" strings for top/left and bottom/right edges, then delegates to the string overload.

Parameters
widthPxBorder thickness in pixels
topLeftColor for top and left edges (highlight)
bottomRightColor for bottom and right edges (shadow)

◆ setGradient()

template<typename T >
void StyleSheet< T >::setGradient ( const QString &  gradient)
inline

Set the background to a gradient string (qradialgradient / qlineargradient).

Parameters
gradientFull CSS gradient value string

Definition at line 63 of file stylesheet.h.

◆ setProperty() [1/2]

template<typename T >
void StyleSheet< T >::setProperty ( StyleSheetProperty  property,
const QColor &  value 
)

Set a stylesheet property to a color value.

Parameters
propertyProperty identifier
valueColor to convert to a CSS color string

◆ setProperty() [2/2]

template<typename T >
void StyleSheet< T >::setProperty ( StyleSheetProperty  property,
const QString &  value 
)

Set a stylesheet property to a string value.

Parameters
propertyProperty identifier
valueString value for the property

◆ setPropertyPixels()

template<typename T >
void StyleSheet< T >::setPropertyPixels ( StyleSheetProperty  property,
int  value 
)

Set a stylesheet property to a pixel integer value.

Parameters
propertyProperty identifier
valueSize in pixels

◆ setPseudoState()

template<typename T >
void StyleSheet< T >::setPseudoState ( StyleSheetPseudoState  value)
inline

Set the pseudo-state selector (e.g., PS_Hover, PS_Checked).

Parameters
valuePseudo-state enum value

Definition at line 109 of file stylesheet.h.

◆ setRadialGradient()

template<typename T >
void StyleSheet< T >::setRadialGradient ( double  cx,
double  cy,
double  radius,
double  fx,
double  fy,
const QGradientStops &  stops 
)

Set the background to a radial gradient specified by its geometric parameters.

Generates a CSS qradialgradient() value from the given parameters and passes it to setGradient(). Colors are converted to rgba() notation so alpha is always preserved.

Parameters
cxCentre x (0–1)
cyCentre y (0–1)
radiusRadius (0–1)
fxFocal-point x (0–1)
fyFocal-point y (0–1)
stopsGradient stops (position in 0–1 and color, including alpha)

◆ setSubControl()

template<typename T >
void StyleSheet< T >::setSubControl ( const QString &  value)
inline

Set the sub-control selector string (e.g., "::handle").

Parameters
valueSub-control string

Definition at line 115 of file stylesheet.h.

◆ toString()

template<typename T >
QString StyleSheet< T >::toString ( ) const

Render all accumulated properties into a complete stylesheet rule.

Returns
Stylesheet string suitable for QWidget::setStyleSheet()

Member Data Documentation

◆ _properties

template<typename T >
QMap<StyleSheetProperty, QString> StyleSheet< T >::_properties

Accumulated property/value pairs for the stylesheet rule.

Definition at line 128 of file stylesheet.h.

◆ _pseudoState

template<typename T >
StyleSheetPseudoState StyleSheet< T >::_pseudoState = PS_Invalid

Pseudo-state selector applied to the rule (PS_Invalid = none).

Definition at line 130 of file stylesheet.h.

◆ _subControl

template<typename T >
QString StyleSheet< T >::_subControl

Sub-control selector string (empty = none).

Definition at line 132 of file stylesheet.h.

◆ _typeName

template<typename T >
QString StyleSheet< T >::_typeName

CSS selector class name (set from T::metaObject()->className()).

Definition at line 125 of file stylesheet.h.


The documentation for this class was generated from the following file: