[PyQt] Understanding PyQt Documentation

Erik Janssens Erik.Janssens at conceptive.be
Fri Sep 20 11:02:28 BST 2013


this might help, I wrote it some time ago as a reminder to myself :)

http://python-
camelot.s3.amazonaws.com/gpl/release/pyqt/doc/advanced/development.html

On Friday, September 20, 2013 09:50:25 PM Chris O'Halloran wrote:

Hello all,


This question will hopefully be trivial but I seem to have a mental block.


I'm currently working through Jan Bodnar's Advanced PyQt tutorial and Mark 
Summerfield's Rapid Gui Application Development with Python and PyQt. Both paid 
for copies. Thanks guys if you're on this list!


I'm a novice programmer but am making reasonable progress and have worked out 
how to embed Matplotlib graphs within PyQt windows and use dials and sliders 
to manipulate the maths in the graphs. Largely through copy and modifying 
others code.


I'm now starting to explore the toolkit beyond the tutorials - although I 
haven't finished either of the works mentioned in the previous paragraph.


But whenever I read the PyQt documentation the following is never clear to me.


This is an example from.

http://pyqt.sourceforge.net/Docs/PyQt4/qpushbutton.html


Say I'm wanting to make a button.


<quote>

Method Documentation
....

QPushButton.__init__ (self, QString text, QWidget parent = None)
The parent argument, if not None, causes self to be owned by Qt instead of 
PyQt.
Constructs a push button with the parent parent and the text text.
</quote>



<code>
from PyQt4 import QtGui

class Pluto(QtGui.QWidget):
    def __init__(self):
        super(Pluto, self).__init__()
        
        self.move(300,300)
        self.setWindowTitle("Size policy")
        
        self.initUI()
        
    def initUI(self):
        
        btn1 = QtGui.QPushButton("Button",self)
        btn1.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        
        btn2 = QtGui.QPushButton("Button2",self)
        

</code>


Now consider
QPushButton.__init__ (self, QString text, QWidget parent = None)
and
btn2 = QtGui.QPushButton("Button2",self)
Obviously "Button" is text and can be a QString and self refers to the a 
QWidget
but I never quite figure out what parent=None means.
Is "QWidget parent=None" all part of one argument?

is parent a key word argument? Ie you can pass other parameter to parent and 
not just 'None'.

Is as simple as self ie the QWidget is simply the parent of the QPushButton so 
that when the QWidget is destroyed the QPushButton is too.

How would you write parent=None?
Would it be
btn2 = QtGui.QPushButton("Button2") 

or is it
btn2 = QtGui.QPushButton("Button2", parent=None) 
btn2 = QtGui.QPushButton("Button2", self, parent=None) 
And, if I write my code
btn2 = QtGui.QPushButton("Button2",self)
and self is the parent argument, ie not None, then I then have no idea what 
self being owned by Qt instead of PyQt actually means.
Given that my code is bog standard, it seems a little odd that tricky things 
are happening with my object being owned by Qt instead of PyQt.

Does this matter or have I interpreted this all incorrectly?
Thanks for your patience if you've read this far.
Cheers and regards,
Chris O'Halloran













-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130920/93a13da9/attachment-0001.html>


More information about the PyQt mailing list