<?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[setStyleSheet - What is it for?]]></title><description><![CDATA[<p dir="auto">Allo all,</p>
<p dir="auto">For example, I can call</p>
<pre><code>pedit=new QLineEdit(this);
pedit-&gt;setGeometry(xEPosition1, yEPosition1+3*yEOffset1, pixelWidth, pixelHeight);
pedit-&gt;setStyleSheet("QLineEdit { border: 1px solid #c8c8ff; border-radius: 3px;} ");
</code></pre>
<p dir="auto">This seems to change the look of the QLineEdit but it seems strange to send a string to an API to setup some states.</p>
<p dir="auto">Why don’t we have</p>
<pre><code>pedit-&gt;SetBorderThickness(1);
pedit-&gt;SetSolidColor(variable);
pedit-&gt;SetBorderRadius(3);
</code></pre>
]]></description><link>https://forum.qt.io/topic/127179/setstylesheet-what-is-it-for</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 12:40:59 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/127179.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 31 May 2021 21:59:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 14:53:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a> said in <a href="/post/662850">setStyleSheet - What is it for?</a>:</p>
<blockquote>
<p dir="auto">Yeah true, but integrating such feature would make the IDE much more "complex".</p>
</blockquote>
<p dir="auto">I don't mean to harp on.  But again for the record I --- and probably the OP --- am interested in <em>runtime</em> support for such features, not (particularly) design-time.  Like <a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a>'s <strong>GammaRay</strong> or a web browser provides.  'Nuff said :)</p>
]]></description><link>https://forum.qt.io/post/662852</link><guid isPermaLink="true">https://forum.qt.io/post/662852</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 01 Jun 2021 14:53:38 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 14:36:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/662833">setStyleSheet - What is it for?</a>:</p>
<blockquote>
<p dir="auto">However, for the record, this is nothing like/to do with what I was talking about using in a web browser.  All the browsers offer "Development Tools" interface.   That does something totally different: you can view and click your page, either visually or in HTML, and be shown where the elements are, and what styles from where are being applied/overridden.  Even nicer, you can interactively check/uncheck boxes for each and every individual style attribute on every element to see its effect, you can modify the styles while you are looking at them and see the response, etc.  Fully interactive.<br />
As someone who did HTML/JS/CSS for years, I found this an invaluable tool in getting my layouts, styles and so on sorted out.  I have thought for years how nice it would be if Qt offered something similar  and friendly for its desktop widgets and styles, but did not find anything acceptable.</p>
</blockquote>
<p dir="auto">Yeah true, but integrating such feature would make the IDE much more "complex".<br />
I'm thinking of something like the <code>Qt::Color</code> behavior in QtCreator: If you hover over a valid <code>QColor</code> string / enum value, a label appears, showing the corresponding color. <strong>That</strong> would be awesome to have with <code>QWidget</code> styles. So that a new window / popup shows up, showing what you can expect from your code (matching the widget you are using the stylesheet on).</p>
]]></description><link>https://forum.qt.io/post/662850</link><guid isPermaLink="true">https://forum.qt.io/post/662850</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Tue, 01 Jun 2021 14:36:05 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 14:04:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Nope.  Didn't really uses it as it wants cmake... and I agree way too complicated to get running but does provide<br />
a huge array of tools.<br />
If it was build into Creator (not sure thats even possible) it would be another story.</p>
<p dir="auto">Edit:<br />
They do supply prebuilds now so maybe its easier than before.</p>
]]></description><link>https://forum.qt.io/post/662845</link><guid isPermaLink="true">https://forum.qt.io/post/662845</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Tue, 01 Jun 2021 14:04:29 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 13:58:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
I thought someone was going to say this!  And again a good point :)</p>
<p dir="auto"><em>However</em>, I tried to use that a while ago, and just didn't get anywhere.  I don't quite recall why.  Was it way too big and complicated complicated?  Did it just not install or work for me?  Did it not work when I was programming in Python/PyQt?</p>
<p dir="auto">So, honest answer: Do you use it?  Regularly? :)</p>
]]></description><link>https://forum.qt.io/post/662843</link><guid isPermaLink="true">https://forum.qt.io/post/662843</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 01 Jun 2021 13:58:48 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 13:55:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Hi<br />
Just as a note.<br />
<a href="https://doc.qt.io/GammaRay/" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/GammaRay/</a><br />
does add a sort of  "Developer Tools" to Qt.</p>
]]></description><link>https://forum.qt.io/post/662837</link><guid isPermaLink="true">https://forum.qt.io/post/662837</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Tue, 01 Jun 2021 13:55:19 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 13:53:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a><br />
I understand what you are saying, and that is a good point.  At least the OP might consider pasting any dynamic stylesheet used at run-time into that box to see what Designer makes of it, better than nothing.</p>
<p dir="auto">However, for the record, this is nothing like/to do with what I was talking about using in a web browser.  All the browsers offer "Development Tools" interface.   That does something totally different: you can view and click your page, either visually or in HTML, and be <em>shown</em> where the elements are, and what styles from where are being applied/overridden.  Even nicer, you can interactively check/uncheck boxes for each and every individual style attribute on every element to see its effect, you can modify the styles while you are looking at them and see the response, etc.  Fully <em>interactive</em>.</p>
<p dir="auto">As someone who did HTML/JS/CSS for years, I found this an <em>invaluable</em> tool in getting my layouts, styles and so on sorted out.  I have thought for years how nice it would be if Qt offered something similar  and friendly for its desktop widgets and styles, but did not find anything acceptable.</p>
]]></description><link>https://forum.qt.io/post/662833</link><guid isPermaLink="true">https://forum.qt.io/post/662833</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 01 Jun 2021 13:53:46 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 13:40:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/662822">setStyleSheet - What is it for?</a>:</p>
<blockquote>
<p dir="auto">Sadly I am aware that Qt does not offer such an interactive examiner, which I miss, but that's how it is.</p>
</blockquote>
<p dir="auto">At least in QtDesigner's <code>Stylesheet</code> "mode", "tab" or whatever it is, it checks if your stylesheet string is a valid stylesheet but unfortunately this does not work dynamically when changing stylesheet in your code (only for preset styles in QtDesigner).</p>
]]></description><link>https://forum.qt.io/post/662830</link><guid isPermaLink="true">https://forum.qt.io/post/662830</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Tue, 01 Jun 2021 13:40:42 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 13:12:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/stretchthebits">@<bdi>stretchthebits</bdi></a><br />
The answer to all of this is, I'm afraid, no, Qt will neither tell you if there is a mistake in your stylesheet, nor if there is where it lies.  In common with, say, HTML page handling, badly formed style directives are simply ignored by the engine.</p>
<p dir="auto">On an HTML page in a browser, like Chrome, there are nice "Developer Tools" which allow you to interactively investigate your styles and play with them responsively.  Sadly I am aware that Qt does not offer such an interactive examiner, which I miss, but that's how it is.</p>
]]></description><link>https://forum.qt.io/post/662822</link><guid isPermaLink="true">https://forum.qt.io/post/662822</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 01 Jun 2021 13:12:44 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 13:01:10 GMT]]></title><description><![CDATA[<p dir="auto">I looked at those pages but apparently, that wasn’t enough for me.<br />
I was calling<br />
pedit-&gt;setStyleSheet(some string)<br />
and nothing was happening.</p>
<p dir="auto">so I guess there were run time errors.<br />
That’s the problem. If the string I give to setStyleSheet() is bad, can it tell me it is bad and which word in the string is bad?</p>
<p dir="auto">Another problem is that the code would compile. The C++ compiler cannot analyze the text I gave to setStyleSheet().</p>
<p dir="auto">For example, if I write<br />
pedit=new QineEdit(this);</p>
<p dir="auto">the compiler would tell me there is a problem with that line.<br />
I get rid of a lot of typing mistakes this way: missing colon and missing parenthesis and much more.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chris-kawa">@<bdi>Chris-Kawa</bdi></a> said in <a href="/post/662754">setStyleSheet - What is it for?</a>:</p>
<blockquote>
<p dir="auto">Maybe its <a href="https://doc.qt.io/qt-5/qlineedit.html#frame-prop" target="_blank" rel="noopener noreferrer nofollow ugc">frame</a> was turned off?</p>
</blockquote>
<p dir="auto">I turned on the frame with a member function call. I think it was<br />
pedit-&gt;setFrame........<br />
but it had no effect.<br />
then, when I started to use setStyleSheet() and this had a real effect on how the edit boxes looked.</p>
<p dir="auto">Thanks for the setMinimumHeight(). I wasn’t aware of that function. Perhaps it would have solved the button height issue.</p>
]]></description><link>https://forum.qt.io/post/662819</link><guid isPermaLink="true">https://forum.qt.io/post/662819</guid><dc:creator><![CDATA[stretchthebits]]></dc:creator><pubDate>Tue, 01 Jun 2021 13:01:10 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 07:00:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/stretchthebits">@<bdi>stretchthebits</bdi></a> said:</p>
<blockquote>
<p dir="auto">I had to search the web to figure out what I am suppose to give to setStyleSheet() and go through a few pages.</p>
</blockquote>
<p dir="auto">The syntax is described <a href="https://doc.qt.io/qt-5/stylesheet-syntax.html" target="_blank" rel="noopener noreferrer nofollow ugc">here</a> and a reference for each widget are listed <a href="https://doc.qt.io/qt-5/stylesheet-reference.html" target="_blank" rel="noopener noreferrer nofollow ugc">here</a>.</p>
<blockquote>
<p dir="auto">I don’t think I have a choice.</p>
</blockquote>
<p dir="auto">You do. You can decide not to use stylesheets ;)</p>
<blockquote>
<p dir="auto">the QLineEdit does not have an entourage</p>
</blockquote>
<p dir="auto">Maybe its <a href="https://doc.qt.io/qt-5/qlineedit.html#frame-prop" target="_blank" rel="noopener noreferrer nofollow ugc">frame</a> was turned off?</p>
<blockquote>
<p dir="auto">As for the QPushButton, the height of the buttons were not right or something</p>
</blockquote>
<p dir="auto">Make sure they are in a proper layout. Also you can change the min/max height of a button, for example <a href="https://doc.qt.io/qt-5/qwidget.html#minimumHeight-prop" target="_blank" rel="noopener noreferrer nofollow ugc">setMinimumHeight</a>.</p>
]]></description><link>https://forum.qt.io/post/662754</link><guid isPermaLink="true">https://forum.qt.io/post/662754</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Tue, 01 Jun 2021 07:00:22 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Tue, 01 Jun 2021 01:37:11 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the answer.</p>
<p dir="auto">Yes, I’ve noticed that it looks like CSS although I’ve never done such web programming.<br />
I guess it is good for someone who knows CSS but it isn’t appropriate for application programmers.<br />
I had to search the web to figure out what I am suppose to give to setStyleSheet() and go through a few pages.</p>
<p dir="auto">“For performance reasons it's best to avoid such small inline stylesheets.”</p>
<p dir="auto">==I don’t think I have a choice. It is only the style of QLineEdit and QPushButton that I want to change.<br />
I am only doing this since for some reason, when I run my app on Linuxes where Qt Creator is not installed, the QLineEdit does not have an entourage.<br />
They just look like white rectangles and it is hard to see them.<br />
I work on Kubuntu 20.10 and I test on Kubuntu 18.04 and  Kubuntu 20.10 and others.</p>
<p dir="auto">As for the QPushButton, the height of the buttons were not right or something. They looked too short. The call to setStyleSheet() helped with this one.</p>
<p dir="auto">I don’t need anything custom and dynamic.<br />
The program just needs to start and just look good.</p>
]]></description><link>https://forum.qt.io/post/662711</link><guid isPermaLink="true">https://forum.qt.io/post/662711</guid><dc:creator><![CDATA[stretchthebits]]></dc:creator><pubDate>Tue, 01 Jun 2021 01:37:11 GMT</pubDate></item><item><title><![CDATA[Reply to setStyleSheet - What is it for? on Mon, 31 May 2021 22:44:10 GMT]]></title><description><![CDATA[<p dir="auto">Qt application uses a QStyle instance to style its widgets. By default the app will create and use a native looking QStyle provided by platform appropriate style plugin.</p>
<p dir="auto">Apart from that Qt also has a QStyleSheetStyle (an internal class). This is a style that styles widgets via user defined properties similar to the CSS syntax from web development. A typical usage is that you provide a separate style file where you define properties for all widgets, their states and subcontrols, similarly as you would when creating a web page. This file would be loaded once and applied to the main application object instance via its <a href="https://doc.qt.io/qt-5/qapplication.html#styleSheet-prop" target="_blank" rel="noopener noreferrer nofollow ugc">setStyleSheet</a>. It would then automatically propagate to all created widgets.</p>
<p dir="auto">That's one way to use it but you can also selectively apply smaller pieces of stylesheets to individual widgets, like in your example. This is similar to inline css styling directly within html. For similar reasons this is not the best way to use it, but an option non the less.</p>
<p dir="auto">So, to answer your questions - you don't have these individual setters on <code>pedit</code> because the widget itself doesn't have those properties, so there's nothing to set there. The line edit itself doesn't store or even know what thickness the border is, what color it has etc. In its paint event it just calls the style method and basically says "hey style, here's a rectangle and a painter. Please paint this rectangle as if it was a line edit". The style then does the rest and paints that rectangle according to rules it was given via that string. When you call <code>setStyleSheet</code> on a widget the only property of it that you're changing is the style it uses. You're changing it from the default native style to the stylesheet style and initialize that style object with supplied string.</p>
<p dir="auto">For performance reasons it's best to avoid such small inline stylesheets. Internally the string is parsed and resulting properties are cached within the style object. Whenever you change the stylesheet it needs to be re-parsed and re-evaluated, which is not a terribly fast operation as you can imagine. If you need to change a look of a control it's better to create a stylesheet that changes the look based on some property of the widget and then only change that property. Most common widget properties are supported out of the box but you can also create custom dynamic properties if you need to.</p>
]]></description><link>https://forum.qt.io/post/662705</link><guid isPermaLink="true">https://forum.qt.io/post/662705</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Mon, 31 May 2021 22:44:10 GMT</pubDate></item></channel></rss>