Package: qtsass310
QtSASS: Compile SCSS files to Qt stylesheetsCopyright © 2015 Yann LanthonyCopyright © 2017–2018 Spyder Project ContributorsTHIS DISTRIBUTION IS DEPRECATEDUseqtsass>=0.3.1instead.OverviewSASSbrings countless amazing features to CSS.
Besides being used in web development, CSS is also the way to stylize Qt-based desktop applications.
However, Qt's CSS has a few variations that prevent the direct use of SASS compiler.The purpose of this tool is to fill the gap between SASS and Qt-CSS by handling those variations.Qt's CSS specificitiesThe goal of QtSASS is to be able to generate a Qt-CSS stylesheet based on a 100% valid SASS file.
This is how it deals with Qt's specifics and how you should modify your CSS stylesheet to use QtSASS."!" in selectorsQt allows to define the style of a widget according to its states, like this:QLineEdit:enabled{...}However, a "not" state is problematic because it introduces an exclamation mark in the selector's name, which is not valid SASS/CSS:QLineEdit:!editable{...}QtSASS allows "!" in selectors' names; the SASS file is preprocessed and any occurence of:!is replaced by:_qnot_(for "Qt not").
However, using this feature prevents from having a 100% valid SASS file, so this support of!might change in the future.
This can be replaced by the direct use of the_qnot_keyword in your SASS file:QLineEdit:_qnot_editable{/* will generate QLineEdit:!editable { */...}qlineargradientThe qlineargradient function also has a non-valid CSS syntax.qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0.1blue,stop:0.8green)To support qlineargradient QtSASS provides a preprocessor and a SASS implementation of the qlineargradient function. The above QSS syntax will be replaced with the following:qlineargradient(0,0,0,1,(0.1blue,0.8green))You may also use this syntax directly in your QtSASS.qlineargradient(0, 0, 0, 1, (0.1 blue, 0.8 green))
# the stops parameter is a list, so you can also use variables:
$stops = 0.1 blue, 0.8 green
qlineargradient(0, 0, 0, 0, $stops)qrgbaQt's rgba:rgba(255,128,128,50%)is replaced by CSS rgba:rgba(255,128,128,0.5)Executable usageTo compile your SASS stylesheet to a Qt compliant CSS file:# If -o is omitted, output will be printed to consoleqtsassstyle.scss-ostyle.cssTo use the watch mode and get your stylesheet auto recompiled on each file save:# If -o is omitted, output will be print to consoleqtsassstyle.scss-ostyle.css-wTo compile a directory containing SASS stylesheets to Qt compliant CSS files:qtsass./static/scss-o./static/cssYou can also use watch mode to watch the entire directory for changes.qtsass./static/scss-o./static/css-wSet the Environment Variable QTSASS_DEBUG to 1 or pass the --debug flag to enable logging.qtsass./static/scss-o./static/css--debugAPI methodscompile(string, **kwargs)Conform and Compile QtSASS source code to CSS.This function conforms QtSASS to valid SCSS before passing it to
sass.compile. Any keyword arguments you provide will be combined with
qtsass's default keyword arguments and passed to sass.compile.Examples:>>>importqtsass
>>>qtsass.compile("QWidget {background: rgb(0, 0, 0);}")QWidget{background:black;}Arguments:string: QtSASS source code to conform and compile.kwargs: Keyword arguments to pass to sass.compileReturns:Qt compliant CSS stringcompile_filename(input_file, dest_file, **kwargs):Compile and save QtSASS file as Qt compliant CSS.Examples:>>>importqtsass
>>>qtsass.compile_filename('dummy.scss','dummy.css')Arguments:input_file: Path to QtSass file.dest_file: Path to destination Qt compliant CSS file.kwargs: Keyword arguments to pass to sass.compilecompile_filename(input_file, output_file, **kwargs):Compile and save QtSASS file as Qt compliant CSS.Examples:>>>importqtsass
>>>qtsass.compile_filename('dummy.scss','dummy.css')Arguments:input_file: Path to QtSass file.output_file: Path to write Qt compliant CSS.kwargs: Keyword arguments to pass to sass.compilecompile_dirname(input_dir, output_dir, **kwargs):Compiles QtSASS files in a directory including subdirectories.>>>importqtsass
>>>qtsass.compile_dirname("./scss","./css")Arguments:input_dir: Path to directory containing QtSass files.output_dir: Directory to write compiled Qt compliant CSS files to.kwargs: Keyword arguments to pass to sass.compileenable_logging(level=None, handler=None):Enable logging for qtsass.Sets the qtsass logger's level to:
1. the provided logging level
2. logging.DEBUG if the QTSASS_DEBUG envvar is a True value
3. logging.WARNING>>>importlogging
>>>importqtsass
>>>handler=logging.StreamHandler()>>>formatter=logging.Formatter('%(level)-8s: %(name)s> %(message)s')>>>handler.setFormatter(formatter)>>>qtsass.enable_logging(level=logging.DEBUG,handler=handler)Arguments:level: Optional logging levelhandler: Optional handler to addwatch(source, destination, compiler=None, Watcher=None):Watches a source file or directory, compiling QtSass files when modified.The compiler function defaults to compile_filename when source is a file
and compile_dirname when source is a directory.Arguments:source: Path to source QtSass file or directory.destination: Path to output css file or directory.compiler: Compile function (optional)Watcher: Defaults to qtsass.watchers.Watcher (optional)Returns:qtsass.watchers.Watcher instanceContributingEveryone is welcome to contribute!SponsorsSpyder and its subprojects are funded thanks to the generous support ofand the donations we have received from our users around the world throughOpen Collective:Please consider becoming a sponsor!