<?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[push buttons are in large numbers]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I have many push buttons (10 nos) and I need to change its style based various conditions, as follows.</p>
<p dir="auto">I'm wondering , Is there a easy way to do this?</p>
<pre><code>   if(value == 0)
            {
                ui-&gt;btn1-&gt;setStyleSheet(StyleSheetOn);
                ui-&gt;btn2-&gt;setStyleSheet(StyleSheetOff);

                .....

                ui-&gt;btn10-&gt;setStyleSheet(StyleSheetOff);
            
            }
            else if(value == 1)
            {
                ui-&gt;btn2-&gt;setStyleSheet(StyleSheetOn);
                ui-&gt;btn1-&gt;setStyleSheet(StyleSheetOff);

                 .....
               
                ui-&gt;btn10-&gt;setStyleSheet(StyleSheetOff);   
        
            }
            else if(value == 2)
            {
                ui-&gt;btn3-&gt;setStyleSheet(StyleSheetOn);
                ui-&gt;btn2-&gt;setStyleSheet(StyleSheetOff);

                .....

                ui-&gt;btn10-&gt;setStyleSheet(StyleSheetOff);             

             }
</code></pre>
]]></description><link>https://forum.qt.io/topic/116888/push-buttons-are-in-large-numbers</link><generator>RSS for Node</generator><lastBuildDate>Fri, 30 Oct 2026 00:17:32 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/116888.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 10 Jul 2020 13:25:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to push buttons are in large numbers on Fri, 10 Jul 2020 15:21:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/russjohn834">@<bdi>russjohn834</bdi></a><br />
Hi<br />
As i wrote, just put them in a extra QWidget and do<br />
QList&lt;QPushButton *&gt; List = TheWidgetHolder-&gt;findChildren&lt;QPushButton *&gt;();<br />
that way you get only the children of the TheWidgetHolder.<br />
If that is too annoying you could also just make the list manually</p>
<p dir="auto">QList&lt;QPushButton *&gt; list{ ui-&gt;bt1, ui-&gt;bt2 .... };</p>
]]></description><link>https://forum.qt.io/post/606061</link><guid isPermaLink="true">https://forum.qt.io/post/606061</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 10 Jul 2020 15:21:56 GMT</pubDate></item><item><title><![CDATA[Reply to push buttons are in large numbers on Fri, 10 Jul 2020 15:16:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> said in <a href="/post/606043">push buttons are in large numbers</a>:</p>
<blockquote>
<p dir="auto">QList&lt;QPushButton *&gt; List = findChildren&lt;QPushButton *&gt;();</p>
</blockquote>
<p dir="auto">Instead getting all the pushbuttons on the screen to a list , how do I add selected push buttons into the list, say push button names are <code>btn_1</code>, <code>btn_2</code>, <code>btn_3</code> etc?</p>
]]></description><link>https://forum.qt.io/post/606060</link><guid isPermaLink="true">https://forum.qt.io/post/606060</guid><dc:creator><![CDATA[russjohn834]]></dc:creator><pubDate>Fri, 10 Jul 2020 15:16:25 GMT</pubDate></item><item><title><![CDATA[Reply to push buttons are in large numbers on Fri, 10 Jul 2020 14:41:59 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
That is the kinda tricky part as they seem to come in creation order.<br />
Meaning in that order that you dragged them to the form.</p>
<p dir="auto">The name is not important in this context.</p>
<p dir="auto">It might be ok already.</p>
<p dir="auto">just dump the list and see.</p>
<p dir="auto">If you use<br />
List[value]-&gt;</p>
<p dir="auto">then value must never be bigger than list.size()-1  ( -1 as it starts with zero)</p>
]]></description><link>https://forum.qt.io/post/606056</link><guid isPermaLink="true">https://forum.qt.io/post/606056</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 10 Jul 2020 14:41:59 GMT</pubDate></item><item><title><![CDATA[Reply to push buttons are in large numbers on Fri, 10 Jul 2020 14:36:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> Thanks a lot for your suggestion.<br />
How do I make sure the button comes in the right order?  what's the correct way to name the push button in this case?</p>
]]></description><link>https://forum.qt.io/post/606054</link><guid isPermaLink="true">https://forum.qt.io/post/606054</guid><dc:creator><![CDATA[russjohn834]]></dc:creator><pubDate>Fri, 10 Jul 2020 14:36:38 GMT</pubDate></item><item><title><![CDATA[Reply to push buttons are in large numbers on Fri, 10 Jul 2020 13:37:26 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
Well if the issue is to turn off all other than the On one, you could do</p>
<pre><code>QList&lt;QPushButton *&gt; List = findChildren&lt;QPushButton *&gt;();
 for (QPushButton * button : List) {
   button-&gt;setStyleSheet(StyleSheetOff);  
 }
</code></pre>
<p dir="auto">Then turn On the single one you want.</p>
<p dir="auto">If you make sure buttons comes in right order then you can also use this way to do the value part.</p>
<p dir="auto">List[value]-&gt;setStyleSheet(StyleSheetOn);</p>
<p dir="auto">But you have to make sure it matches up or it will crash :)<br />
so button 1 will be in index zero etc.</p>
<p dir="auto">If you have more Buttons on the form than you want in list then you can add a widget to hold the buttons you want to affect and use</p>
<p dir="auto">QList&lt;QPushButton *&gt; List = TheWidgetHolder-&gt;findChildren&lt;QPushButton *&gt;();</p>
<p dir="auto">So we only ask that widget about buttons and not the whole of mainwindow.</p>
]]></description><link>https://forum.qt.io/post/606043</link><guid isPermaLink="true">https://forum.qt.io/post/606043</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 10 Jul 2020 13:37:26 GMT</pubDate></item></channel></rss>