<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PyQt &#8211; Signals, Slots and Layouts Tutorial</title>
	<atom:link href="http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/</link>
	<description>Memoirs of a QWERTY Keyboard</description>
	<lastBuildDate>Sat, 21 Jan 2012 16:18:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Harsh</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-76300</link>
		<dc:creator>Harsh</dc:creator>
		<pubDate>Tue, 08 Feb 2011 03:45:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-76300</guid>
		<description>Yes, in a Python class, you always work with the method&#039;s first argument (being the instance) - generally referred to as &#039;self&#039;.</description>
		<content:encoded><![CDATA[<p>Yes, in a Python class, you always work with the method&#8217;s first argument (being the instance) &#8211; generally referred to as &#8216;self&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blahah</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-76270</link>
		<dc:creator>Blahah</dc:creator>
		<pubDate>Sat, 05 Feb 2011 20:09:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-76270</guid>
		<description>I realised the problem as soon as I read your reply - &quot;all *methods* are usable as slots&quot;. I had created a class which extended QPushButton, but then I didn&#039;t create an instance of my class. So I thought I was trying to call a function - I should have been calling the method of my instance.

Note to self: always work with instances!

Thanks for all the help, Harsh.</description>
		<content:encoded><![CDATA[<p>I realised the problem as soon as I read your reply &#8211; &#8220;all *methods* are usable as slots&#8221;. I had created a class which extended QPushButton, but then I didn&#8217;t create an instance of my class. So I thought I was trying to call a function &#8211; I should have been calling the method of my instance.</p>
<p>Note to self: always work with instances!</p>
<p>Thanks for all the help, Harsh.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harsh</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-76269</link>
		<dc:creator>Harsh</dc:creator>
		<pubDate>Sat, 05 Feb 2011 20:03:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-76269</guid>
		<description>@Blahah - All methods are usable as slots without needing a &#039;registration&#039; of any kind (You do need registrations for signals, however).

For a deeper example, check &lt;a href=&quot;http://www.harshj.com/2010/05/06/pyqt-faq-custom-signals-jpeg-mouse-hovers-and-more/#custom&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt;. Hope that helps clear your instance issue :)</description>
		<content:encoded><![CDATA[<p>@Blahah &#8211; All methods are usable as slots without needing a &#8216;registration&#8217; of any kind (You do need registrations for signals, however).</p>
<p>For a deeper example, check <a href="http://www.harshj.com/2010/05/06/pyqt-faq-custom-signals-jpeg-mouse-hovers-and-more/#custom" rel="nofollow">this</a>. Hope that helps clear your instance issue <img src='http://www.harshj.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blahah</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-76267</link>
		<dc:creator>Blahah</dc:creator>
		<pubDate>Sat, 05 Feb 2011 14:15:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-76267</guid>
		<description>Also, I tried to extend the class as per your instructions but I couldn&#039;t work out how to register a function of a class as a slot - there seem to be two different signal/slot systems in PyQt and neither specifies how to do this in the docs.</description>
		<content:encoded><![CDATA[<p>Also, I tried to extend the class as per your instructions but I couldn&#8217;t work out how to register a function of a class as a slot &#8211; there seem to be two different signal/slot systems in PyQt and neither specifies how to do this in the docs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blahah</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-76266</link>
		<dc:creator>Blahah</dc:creator>
		<pubDate>Sat, 05 Feb 2011 14:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-76266</guid>
		<description>Hi again Harsh. I *finally* got this to work:

from PyQt4.QtGui import QWidget, QPushButton, QHBoxLayout, QApplication
from PyQt4.QtCore import SIGNAL, SLOT
import sys

if __name__==&#039;__main__&#039;:
    
    app = QApplication(sys.argv)
    window = QWidget()
    button = QPushButton(&quot;Hello&quot;)
    layout = QHBoxLayout(window)
    layout.addWidget(button)
        
    def toggler():
            if button.text() == &quot;Hello&quot;:
                button.setText(&quot;PyQt&quot;)
            else:
                button.setText(&quot;Hello&quot;)
    
    button.connect(button, SIGNAL(&quot;clicked()&quot;), toggler)
      
    window.show()
    
    app.exec_()

But I can&#039;t make it work without the toggler() function explicitly referring to the button instance. I wanted to make it so the toggler function was passed the name of the instance by the signal.

I tried:
    def toggler(x):
            if x.text() == &quot;Hello&quot;:
                x.setText(&quot;PyQt&quot;)
            else:
                x.setText(&quot;Hello&quot;)
    
    button.connect(button, SIGNAL(&quot;clicked()&quot;), toggler(button))

I don&#039;t understand why I can&#039;t do this, and what I would have to do differently to make it work.

Sorry for flooding your comments recently, but hey at least you know your blog is teaching someone PyQt :)</description>
		<content:encoded><![CDATA[<p>Hi again Harsh. I *finally* got this to work:</p>
<p>from PyQt4.QtGui import QWidget, QPushButton, QHBoxLayout, QApplication<br />
from PyQt4.QtCore import SIGNAL, SLOT<br />
import sys</p>
<p>if __name__==&#8217;__main__&#8217;:</p>
<p>    app = QApplication(sys.argv)<br />
    window = QWidget()<br />
    button = QPushButton(&#8220;Hello&#8221;)<br />
    layout = QHBoxLayout(window)<br />
    layout.addWidget(button)</p>
<p>    def toggler():<br />
            if button.text() == &#8220;Hello&#8221;:<br />
                button.setText(&#8220;PyQt&#8221;)<br />
            else:<br />
                button.setText(&#8220;Hello&#8221;)</p>
<p>    button.connect(button, SIGNAL(&#8220;clicked()&#8221;), toggler)</p>
<p>    window.show()</p>
<p>    app.exec_()</p>
<p>But I can&#8217;t make it work without the toggler() function explicitly referring to the button instance. I wanted to make it so the toggler function was passed the name of the instance by the signal.</p>
<p>I tried:<br />
    def toggler(x):<br />
            if x.text() == &#8220;Hello&#8221;:<br />
                x.setText(&#8220;PyQt&#8221;)<br />
            else:<br />
                x.setText(&#8220;Hello&#8221;)</p>
<p>    button.connect(button, SIGNAL(&#8220;clicked()&#8221;), toggler(button))</p>
<p>I don&#8217;t understand why I can&#8217;t do this, and what I would have to do differently to make it work.</p>
<p>Sorry for flooding your comments recently, but hey at least you know your blog is teaching someone PyQt <img src='http://www.harshj.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blahah</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-76246</link>
		<dc:creator>Blahah</dc:creator>
		<pubDate>Wed, 02 Feb 2011 17:27:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-76246</guid>
		<description>Thanks for the feedback, I think I&#039;m making progress here... (I&#039;m a newbie at programming/python/PyQt)

Trying to take on board your advice, I came up with this:
from PyQt4.QtGui import QWidget, QPushButton, QHBoxLayout, QApplication
from PyQt4.QtCore import SIGNAL, SLOT
import sys

if __name__==&#039;__main__&#039;:
    
    app = QApplication(sys.argv)
    
    window = QWidget()
    window.setWindowTitle(&quot;Layouts 1&quot;)
    button = QPushButton(&quot;Hello&quot;)
    layout = QHBoxLayout(window)
    
    class Toggle(QPushButton):
        
        def toggleText(self):
            if button.text() == &quot;Hello&quot;:
                button.setText(&quot;PyQt&quot;)
            else:
                button.setText(&quot;Hello&quot;)
        
    layout.addWidget(button)
    button.connect(button, SIGNAL(&quot;clicked()&quot;),\
                   button, SLOT(&quot;toggleText()&quot;))
    window.show()
    
    app.exec_()
The program runs with the error &#039;No such slot QPushButton::toggleText()&#039;.
Have I extended the class correctly? Do I need to define an __init__ for my class? Sorry for coming back for more help, it&#039;s quite baffling trying to get my head around the documentation.</description>
		<content:encoded><![CDATA[<p>Thanks for the feedback, I think I&#8217;m making progress here&#8230; (I&#8217;m a newbie at programming/python/PyQt)</p>
<p>Trying to take on board your advice, I came up with this:<br />
from PyQt4.QtGui import QWidget, QPushButton, QHBoxLayout, QApplication<br />
from PyQt4.QtCore import SIGNAL, SLOT<br />
import sys</p>
<p>if __name__==&#8217;__main__&#8217;:</p>
<p>    app = QApplication(sys.argv)</p>
<p>    window = QWidget()<br />
    window.setWindowTitle(&#8220;Layouts 1&#8243;)<br />
    button = QPushButton(&#8220;Hello&#8221;)<br />
    layout = QHBoxLayout(window)</p>
<p>    class Toggle(QPushButton):</p>
<p>        def toggleText(self):<br />
            if button.text() == &#8220;Hello&#8221;:<br />
                button.setText(&#8220;PyQt&#8221;)<br />
            else:<br />
                button.setText(&#8220;Hello&#8221;)</p>
<p>    layout.addWidget(button)<br />
    button.connect(button, SIGNAL(&#8220;clicked()&#8221;),\<br />
                   button, SLOT(&#8220;toggleText()&#8221;))<br />
    window.show()</p>
<p>    app.exec_()<br />
The program runs with the error &#8216;No such slot QPushButton::toggleText()&#8217;.<br />
Have I extended the class correctly? Do I need to define an __init__ for my class? Sorry for coming back for more help, it&#8217;s quite baffling trying to get my head around the documentation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harsh</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-76227</link>
		<dc:creator>Harsh</dc:creator>
		<pubDate>Sun, 30 Jan 2011 16:26:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-76227</guid>
		<description>Hey Blahah,

QAbstractButton.text() returns the QString text. Note that all properties of a class available in Qt can be got via property() and set via setProperty() [No &#039;get&#039; business, like in Java] :)

2nd point is right. Registered slots of a class have a &#039;signature&#039;, (as in, &quot;clicked()&quot;, etc.), so you can&#039;t push in functions into them to execute. Try the same approach by extending the class QPushButton and adding in a new method inside, instead of using an external function. This way you&#039;d also learn how to extend/improve base Qt classes for your needs, as is the philosophy :)</description>
		<content:encoded><![CDATA[<p>Hey Blahah,</p>
<p>QAbstractButton.text() returns the QString text. Note that all properties of a class available in Qt can be got via property() and set via setProperty() [No 'get' business, like in Java] <img src='http://www.harshj.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>2nd point is right. Registered slots of a class have a &#8216;signature&#8217;, (as in, &#8220;clicked()&#8221;, etc.), so you can&#8217;t push in functions into them to execute. Try the same approach by extending the class QPushButton and adding in a new method inside, instead of using an external function. This way you&#8217;d also learn how to extend/improve base Qt classes for your needs, as is the philosophy <img src='http://www.harshj.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blahah</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-76194</link>
		<dc:creator>Blahah</dc:creator>
		<pubDate>Fri, 28 Jan 2011 17:37:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-76194</guid>
		<description>For the purpose fo the exercise, is there some way I can read the text of the button?

I tried the following:
from PyQt4.QtGui import QWidget, QPushButton, QHBoxLayout, QApplication
from PyQt4.QtCore import SIGNAL, SLOT
import sys

if __name__==&#039;__main__&#039;:
    
    app = QApplication(sys.argv)
    
    window = QWidget()
    window.setWindowTitle(&quot;Layouts Ex. 1&quot;)
    button = QPushButton(&quot;Hello&quot;)
    layout = QHBoxLayout(window)
    
    def toggle():
        if button[&quot;text&quot;] == &quot;Hello&quot;:
            return &quot;PyQt&quot;
        else:
            return &quot;Hello&quot;
        
    layout.addWidget(button)
    button.connect(button, SIGNAL(&quot;clicked()&quot;),\
                   button, SLOT(&quot;setText(toggle())&quot;))
    window.show()
    
    app.exec_()

Obviously it doesn&#039;t work, for one or both of these reasons:
- button[&quot;text&quot;] doesn&#039;t return the text of the button (it was a complete guess as I couldn&#039;t figure out where to find this info in the docs)
- maybe you can&#039;t call a function in a slot like I tried to do with toggle()

Can you give me a pointer?

-Blahah

p.s. nice tutorial thanks, PyQt and python really starting to make sense after reading through your articles.</description>
		<content:encoded><![CDATA[<p>For the purpose fo the exercise, is there some way I can read the text of the button?</p>
<p>I tried the following:<br />
from PyQt4.QtGui import QWidget, QPushButton, QHBoxLayout, QApplication<br />
from PyQt4.QtCore import SIGNAL, SLOT<br />
import sys</p>
<p>if __name__==&#8217;__main__&#8217;:</p>
<p>    app = QApplication(sys.argv)</p>
<p>    window = QWidget()<br />
    window.setWindowTitle(&#8220;Layouts Ex. 1&#8243;)<br />
    button = QPushButton(&#8220;Hello&#8221;)<br />
    layout = QHBoxLayout(window)</p>
<p>    def toggle():<br />
        if button["text"] == &#8220;Hello&#8221;:<br />
            return &#8220;PyQt&#8221;<br />
        else:<br />
            return &#8220;Hello&#8221;</p>
<p>    layout.addWidget(button)<br />
    button.connect(button, SIGNAL(&#8220;clicked()&#8221;),\<br />
                   button, SLOT(&#8220;setText(toggle())&#8221;))<br />
    window.show()</p>
<p>    app.exec_()</p>
<p>Obviously it doesn&#8217;t work, for one or both of these reasons:<br />
- button["text"] doesn&#8217;t return the text of the button (it was a complete guess as I couldn&#8217;t figure out where to find this info in the docs)<br />
- maybe you can&#8217;t call a function in a slot like I tried to do with toggle()</p>
<p>Can you give me a pointer?</p>
<p>-Blahah</p>
<p>p.s. nice tutorial thanks, PyQt and python really starting to make sense after reading through your articles.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harsh</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-75484</link>
		<dc:creator>Harsh</dc:creator>
		<pubDate>Sun, 07 Nov 2010 05:53:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-75484</guid>
		<description>Yep, looks like my CMS played funny while translating that code for formatting in comments. (One could use pre tags though).

But anyways, that line isn&#039;t needed in interpreter mode.</description>
		<content:encoded><![CDATA[<p>Yep, looks like my CMS played funny while translating that code for formatting in comments. (One could use pre tags though).</p>
<p>But anyways, that line isn&#8217;t needed in interpreter mode.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gordonian</title>
		<link>http://www.harshj.com/2009/05/14/pyqt-signals-slots-and-layouts-tutorial/comment-page-1/#comment-75461</link>
		<dc:creator>Gordonian</dc:creator>
		<pubDate>Sun, 31 Oct 2010 14:01:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.harshj.com/?p=551#comment-75461</guid>
		<description>I am not sure what character Helvin is using, but it does not appear to be a single quote, because the interactive python interpreter on my box won&#039;t accept it.  I presume that is the problem with the code from July of last year that nobody responded to...

  File &quot;&quot;, line 1
    if __name__==’__main__’:
                 ^
SyntaxError: invalid syntax
</description>
		<content:encoded><![CDATA[<p>I am not sure what character Helvin is using, but it does not appear to be a single quote, because the interactive python interpreter on my box won&#8217;t accept it.  I presume that is the problem with the code from July of last year that nobody responded to&#8230;</p>
<p>  File &#8220;&#8221;, line 1<br />
    if __name__==’__main__’:<br />
                 ^<br />
SyntaxError: invalid syntax</p>
]]></content:encoded>
	</item>
</channel>
</rss>

