<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Is there any method to define a variable in QSS file?]]></title><description><![CDATA[<p dir="auto">As the topic, how to define a variable in qss.<br />
just like #define    FONT_SIZE     16px</p>
]]></description><link>https://forum.qt.io/topic/93519/is-there-any-method-to-define-a-variable-in-qss-file</link><generator>RSS for Node</generator><lastBuildDate>Wed, 13 May 2026 17:56:02 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/93519.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Aug 2018 08:47:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is there any method to define a variable in QSS file? on Thu, 09 Aug 2018 09:42:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> Thanks, Let me try.</p>
]]></description><link>https://forum.qt.io/post/474938</link><guid isPermaLink="true">https://forum.qt.io/post/474938</guid><dc:creator><![CDATA[brucezcg]]></dc:creator><pubDate>Thu, 09 Aug 2018 09:42:41 GMT</pubDate></item><item><title><![CDATA[Reply to Is there any method to define a variable in QSS file? on Thu, 09 Aug 2018 09:04:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/brucezcg">@<bdi>brucezcg</bdi></a><br />
Nope (nor in CSS) :( .</p>
<p dir="auto">You won't like this, but I have faced this problem.  I do my work direct from Qt widgets, no QML/Qt Quick, so I don't know whether this is useful/applicable to you or not.  I actually "pre-process" my QSS stylesheet file(s), before handing them off to <code>QtWidgets.QApplication.instance().setStyleSheet(css)</code> in code.  So for example example my primary QSS file starts with:</p>
<pre><code>/* Set the base font size for all widgets */
* {
    font-size: &lt;FONT_SIZE&gt;pt;
}
</code></pre>
<p dir="auto">and my code, having read the file content into <code>css</code> variable, is like:</p>
<pre><code>    # substitute all "&lt;FONT_SIZE&gt;" with the actual font size wanted
    fontSize = Settings.current().getDefaultFontSize()
    css = css.replace("&lt;FONT_SIZE&gt;", fontSize)
    biggerFontSize = Settings.current().getDefaultBiggerFontSize()
    css = css.replace("&lt;BIGGER_FONT_SIZE&gt;", biggerFontSize)
    ...
    QtWidgets.QApplication.instance().setStyleSheet(css)
</code></pre>
]]></description><link>https://forum.qt.io/post/474922</link><guid isPermaLink="true">https://forum.qt.io/post/474922</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 09 Aug 2018 09:04:24 GMT</pubDate></item></channel></rss>