<?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[Activating a button]]></title><description><![CDATA[<p dir="auto">I have created a form (form.ui) using the drag and drop features of QT Creator.</p>
<p dir="auto">To access these objects, I define a local object within my code and, thanks to the help of others, have done so through a loop:</p>
<pre><code>def initialise(self):

    dataItems = ['lunit', 'lfile', 'kunit', 'sfile', 'junit']
    self.fv_dict = {}

    for dataItem in dataItems:
        self.fv_dict[dataItem] = self.window.findChild(QLineEdit, dataItem)
        self.fv_dict[dataItem].textEdited.connect(textedited)
</code></pre>
<p dir="auto">The rest of this subroutine reads in a CSV textfile and assigns the values from that CSV file to each of the QLineEdits on the form (I have shortened the number of QLineEdits above to 5; there are, in fact, over 60).</p>
<p dir="auto">I have gotten the system to trigger an event when any of the textboxes have their contents changed by the user (given with the connect shown above and running the following code).</p>
<pre><code>def textedited(text):
    
    print(text)
</code></pre>
<p dir="auto">So far, so good.</p>
<p dir="auto">I have added two buttons to the form using the drag and drop interface; calling them saveChanges and discardChanges. I have disabled both buttons.</p>
<p dir="auto">I want to have the buttons enabled if any of the QLineEdit's have their contents changed; thus using the triggered event I have shown above.</p>
<p dir="auto">I tried declaring the objects in the subroutine above, changing the single parameter to 'self' and adding this to the connect statement previously...</p>
<pre><code>def initialise(self):

    dataItems = ['lunit', 'lfile', 'kunit', 'sfile', 'junit']
    self.fv_dict = {}

    for dataItem in dataItems:
        self.fv_dict[dataItem] = self.window.findChild(QLineEdit, dataItem)
        self.fv_dict[dataItem].textEdited.connect(textedited(self))
....

def textedited(self):

    self.saveButton = self.window.findChild(QPushButton, 'SaveChanges')
    self.discardButton = self.window.findChild(QPushButton, 'DiscardChanges')
</code></pre>
<p dir="auto">This appears to run fine; no errors. Not convinced I should have to declare these objects each and every time the contents of a QLineEdit is changed, but this appears to be the nature of the beast (given my limited understanding at present).</p>
<p dir="auto">I then add a setEnabled to the end of that function...</p>
<pre><code>def textedited(self):

    self.saveButton = self.window.findChild(QPushButton, 'SaveChanges')
    self.discardButton = self.window.findChild(QPushButton, 'DiscardChanges')

    self.saveButton.setEnabled(True)
</code></pre>
<p dir="auto">And now this won't run:</p>
<pre><code>AttributeError: 'NoneType' object has no attribute 'setEnabled'
</code></pre>
<p dir="auto">Where am I going wrong?</p>
]]></description><link>https://forum.qt.io/topic/137084/activating-a-button</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 16:58:40 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/137084.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 Jun 2022 09:12:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Activating a button on Wed, 08 Jun 2022 11:09:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/garyn">@<bdi>GaryN</bdi></a> said in <a href="/post/716873">Activating a button</a>:</p>
<blockquote>
<p dir="auto">AttributeError: 'NoneType' object has no attribute 'setEnabled'</p>
</blockquote>
<p dir="auto">So the</p>
<pre><code>self.saveButton = self.window.findChild(QPushButton, 'SaveChanges')
</code></pre>
<p dir="auto">returned <code>None</code>, i.e. no <code>QPushButton</code> named <code>SaveChanges</code> was found....  Did you create the button, put it in <code>self.window</code>, and what did you set its <code>objectName</code> to?</p>
]]></description><link>https://forum.qt.io/post/716896</link><guid isPermaLink="true">https://forum.qt.io/post/716896</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 08 Jun 2022 11:09:48 GMT</pubDate></item><item><title><![CDATA[Reply to Activating a button on Sun, 12 Jun 2022 14:41:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a></p>
<p dir="auto">Capitalised D and S!</p>
<p dir="auto">Sometimes just having someone asking questions makes you look again differently.</p>
<p dir="auto">Thank you.</p>
]]></description><link>https://forum.qt.io/post/717256</link><guid isPermaLink="true">https://forum.qt.io/post/717256</guid><dc:creator><![CDATA[GaryN]]></dc:creator><pubDate>Sun, 12 Jun 2022 14:41:39 GMT</pubDate></item><item><title><![CDATA[Reply to Activating a button on Wed, 08 Jun 2022 11:09:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/garyn">@<bdi>GaryN</bdi></a> said in <a href="/post/716873">Activating a button</a>:</p>
<blockquote>
<p dir="auto">AttributeError: 'NoneType' object has no attribute 'setEnabled'</p>
</blockquote>
<p dir="auto">So the</p>
<pre><code>self.saveButton = self.window.findChild(QPushButton, 'SaveChanges')
</code></pre>
<p dir="auto">returned <code>None</code>, i.e. no <code>QPushButton</code> named <code>SaveChanges</code> was found....  Did you create the button, put it in <code>self.window</code>, and what did you set its <code>objectName</code> to?</p>
]]></description><link>https://forum.qt.io/post/716896</link><guid isPermaLink="true">https://forum.qt.io/post/716896</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 08 Jun 2022 11:09:48 GMT</pubDate></item></channel></rss>