[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.

1)

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?

2)

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?

3)

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?

4)

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?

5)

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

6)

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?

7)

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?

8)

Finally, is there any performance difference between

from PyQt4 import QtCore, QtGui

and

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

Thanks for PyQt and your help.

Shriramana Sharma.



More information about the PyQt mailing list