Skip to content

DigitalArtifex/QVariableStyleSheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QVariableStyleSheet

QVariableStyleSheet is a small library that enables CSS-compliant variable processing in your Qt/PyQT/PySide Style Sheets.

Usage (C++)

    //Include the header
    #include "QVariableSytleSheet/qvariablestylesheet.h"
    
    //Load QSS data from file or resource
    QString theme = file.readAll();

    /*
        Declare the variable style sheet.
        Data is set in the constructor or
            through the sheet.setStyleSheet() function
    */
    QVariableStyleSheet sheet(theme);
    QString processedTheme = sheet.process();
    this->setStyleSheet(processedTheme);

Usage (python)

    # Include the header
    from qvariablestylesheet import QVariableStyleSheet
    
    # Load QSS data from file or resource
    theme = open("stylesheet.qss", 'r').read()  # type: str

    """
    Declare the variable style sheet.
    Data is set in the constructor or through the sheet.setStyleSheet() function
    """
    sheet = QVariableStyleSheet(theme)  # type: QVariableStyleSheet
    processedTheme = sheet.process()  # type: str
    print(processedTheme)
    self.setStyleSheet(processedTheme)

Usage (QtStyleSheet)

    /*
        Declare variable data in the :root block.
        According to CSS: each variable MUST start with "--"
    */
    :root
    {
        --window-backgound-color: #141414;
        --widget-background-color: #242424;
        --widget-border-size: 2;
        --widget-border-color-1: #4b4b4b;
        --widget-border-color-2: #141414;
        --subwidget-border-color-1: #4b4b4b;
        --subwidget-border-color-2: #141414;
        --subwidget-background-color: #141414;
        --page-background-color: #111111; 
    }
    
    /*
        Use variables in your style blocks
    */
    QWidget
    {
        background-color: var(--widget-background-color);
        border-left: var(--widget-border-size) solid black;
        border-top: var(--widget-border-size) solid black;
        border-right: var(--widget-border-size) solid black;
        border-bottom: var(--widget-border-size) solid black;
        border-right-color: qlineargradient(x1:1, y1:0, x2:0, y2:0, stop: 0 var(--widget-border-color-1), stop: 1 var(--widget-border-color-2));
        border-left-color: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop: 0 var(--widget-border-color-1), stop: 1 var(--widget-border-color-2));
        border-top-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 var(--widget-border-color-1), stop: 1 var(--widget-border-color-2));
        border-bottom-color: qlineargradient(x1:0, y1:1, x2:0, y2:0, stop: 0 var(--widget-border-color-1), stop: 1 var(--widget-border-color-2));
    }

About

CSS variable processing support for QSS files

Resources

License

Stars

2 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors