<?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[Why is the style so strange?]]></title><description><![CDATA[<p dir="auto">Hello,<br />
This is the code.</p>
<pre><code>    QApplication a(argc, argv);
    QPushButton* button = new QPushButton("Click Me");
    button-&gt;setStyleSheet("QPushButton:checked{ background: red; }QPushButton:unchecked{ background: green; }"); 
    button-&gt;setCheckable(true);
    button-&gt;setChecked(true);
    button-&gt;show();
    return a.exec();
</code></pre>
<p dir="auto">and this is the button<br />
<img src="https://ddgobkiprc33d.cloudfront.net/77b6f317-9c96-4757-a5c1-ac57a8fa4c68.gif" alt="动画.gif" class=" img-fluid img-markdown" /><br />
I was confused.the qt version is5.14.2,the console print("QWindowsWindow::setGeometry: Unable to set geometry 93x28+960+450 (frame: 111x75+951+412) on QWidgetWindow/"QPushButtonClassWindow" on "\.\DISPLAY1". Resulting geometry: 152x28+960+450 (frame: 170x75+951+412) margins: 9, 38, 9, 9)")<br />
Thanks.</p>
]]></description><link>https://forum.qt.io/topic/145917/why-is-the-style-so-strange</link><generator>RSS for Node</generator><lastBuildDate>Tue, 03 Nov 2026 01:21:36 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/145917.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 21 Jun 2023 06:00:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Why is the style so strange? on Thu, 22 Jun 2023 20:42:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/john-van">@<bdi>John-Van</bdi></a> Most of the time setting any qss property disables the native style entirely, but for some properties that the native style can handle Qt will try to use those. This is the case with a button background. The grid-like pattern you see is part of the native checked style. You can disable native style entirely by setting some other property, e.g. a border.</p>
<p dir="auto">Second thing is that the <code>:unchecked</code> style doesn't seem to apply to all types of widgets. It doesn't work for buttons. To style unchecked button just don't specify the state, so combining those two things you can style it like this:</p>
<pre><code class="language-cpp">"QPushButton { border:none; background: green; }
 QPushButton:checked { background: red; }"
</code></pre>
<p dir="auto">As for the message - it's unrelated to the styling. It means that Qt calculated the size for the button and tried to create a window of that size, but it was smaller than a minimum allowed window size, so the button was enlarged to meet that minimum. Native windows have a minimum size dictated by the style of the frame - whether it has close, min/max buttons and an icon. It's safe to ignore this message. If you want to avoid it make sure you resize your widget to above that minimum before you show the widget, or change the window flags not to include those frame elements that dictate minimum size if you don't need them.</p>
]]></description><link>https://forum.qt.io/post/762380</link><guid isPermaLink="true">https://forum.qt.io/post/762380</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Thu, 22 Jun 2023 20:42:10 GMT</pubDate></item><item><title><![CDATA[Reply to Why is the style so strange? on Sun, 25 Jun 2023 01:28:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chris-kawa">@<bdi>Chris-Kawa</bdi></a> Thank you so much.</p>
]]></description><link>https://forum.qt.io/post/762537</link><guid isPermaLink="true">https://forum.qt.io/post/762537</guid><dc:creator><![CDATA[John Van]]></dc:creator><pubDate>Sun, 25 Jun 2023 01:28:20 GMT</pubDate></item><item><title><![CDATA[Reply to Why is the style so strange? on Thu, 22 Jun 2023 20:42:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/john-van">@<bdi>John-Van</bdi></a> Most of the time setting any qss property disables the native style entirely, but for some properties that the native style can handle Qt will try to use those. This is the case with a button background. The grid-like pattern you see is part of the native checked style. You can disable native style entirely by setting some other property, e.g. a border.</p>
<p dir="auto">Second thing is that the <code>:unchecked</code> style doesn't seem to apply to all types of widgets. It doesn't work for buttons. To style unchecked button just don't specify the state, so combining those two things you can style it like this:</p>
<pre><code class="language-cpp">"QPushButton { border:none; background: green; }
 QPushButton:checked { background: red; }"
</code></pre>
<p dir="auto">As for the message - it's unrelated to the styling. It means that Qt calculated the size for the button and tried to create a window of that size, but it was smaller than a minimum allowed window size, so the button was enlarged to meet that minimum. Native windows have a minimum size dictated by the style of the frame - whether it has close, min/max buttons and an icon. It's safe to ignore this message. If you want to avoid it make sure you resize your widget to above that minimum before you show the widget, or change the window flags not to include those frame elements that dictate minimum size if you don't need them.</p>
]]></description><link>https://forum.qt.io/post/762380</link><guid isPermaLink="true">https://forum.qt.io/post/762380</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Thu, 22 Jun 2023 20:42:10 GMT</pubDate></item><item><title><![CDATA[Reply to Why is the style so strange? on Thu, 22 Jun 2023 18:00:50 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm not sure what your question is, but based on your code, this might provide an answer:</p>
<p dir="auto"><a href="https://forum.qt.io/post/662087">QPushButton: changing icon via setStyleSheet</a></p>
]]></description><link>https://forum.qt.io/post/762361</link><guid isPermaLink="true">https://forum.qt.io/post/762361</guid><dc:creator><![CDATA[CPPUIX]]></dc:creator><pubDate>Thu, 22 Jun 2023 18:00:50 GMT</pubDate></item></channel></rss>