[PyQt] Questions about the PyQt examples

Shriramana Sharma samjnaa at gmail.com
Sun Mar 18 16:58:12 GMT 2007

I have some questions as to the PyQt examples. Since I was practically
offline for months on end I was not able to ask these questions when I
was doing the examples. So please read patiently and answer. Thank you.


In #04, "self." is used repeatedly for setFixedSize, quit=QPushButton
etc, whereas it is not similarly used in #05 - for lcd, slider etc. Why?
Similarly, in #07, "self." is used for slider but not for lcd. Is there
a reason?


In #08, two lines are not translated to Python from the C++ Qt example:

lcd . setSegmentStyle ( QLCDNumber . Filled ) # missing in provided example
self . setAutoFillBackground ( True ) # missing in provided example

Is there a particular reason?


In the same #08, if I remove the word self from the line:

self.emit(QtCore.SIGNAL("angleChanged(int)"), self.currentAngle)

I get an error:

Traceback (most recent call last):
   File "./008.py.showserror-buthowdoesitwork", line 62, in setAngle
     self . emit ( SIGNAL ( "angleChanged ( int )" ), currentAngle )
NameError: global name 'currentAngle' is not defined

But the program still works normally. How?


In #02, the last but one line has a semicolon at the end. This is C
syntax, not Python syntax. But still Python executes the program without
any warning or error. How?


Why do the tutorials not use tr() for user visible strings?


I observed that a large part of the functions in the PyQt API take self
as the first object (to emphasize that it should be called only on an
instance of the class) but the calls in the examples do not include self
as the first item. How is it that Python doesn't throw any errors?


If there is no need to include "self", then why is it necessary to say
"self" in the QWidget __init__ constructor whenever I subclass QWidget
within PyQt?


Finally, is there any performance difference between

from PyQt4 import QtCore, QtGui


from PyQt4.QtCore import *
from PyQt4.QtGui import *

Thanks for PyQt and your help.

Shriramana Sharma.

More information about the PyQt mailing list