<div dir="ltr"><div><div><div><div>class SLD_sequence_scene(QtGui.QGraphicsScene):<br><br>    def __init__(self,x,y,w,h,<b>parent=None</b>):<br>        super(SLD_sequence_scene, self).__init__(x,y,w,h<b>,parent</b>) #  to enable the program to exit gracefully<br>        <br>        print("the scene parent is {0}".format(self.parent()))<br>        <br>        <br>class SLD_label(QtGui.QLineEdit):<br>    def __init__(self):<br>        super(SLD_label, self).__init__()<br>        self.setGeometry(0,0,70,15)<br><br><br><br>class SLD_sequence_view(QtGui.QGraphicsView):<br><br>    def __init__(self, parent=None):<br>        super(SLD_sequence_view, self).__init__(parent)<br>        <br>        self.setGeometry(0,0,1000,1000)<br>        self.scene = SLD_sequence_scene(0,0,1000,900<b>,self</b>)<br>        self.setScene(self.scene)  <br>        #self.d={}<br><br></div>Hello all,<br><br></div>I was trying to track down why my program wouldn't shut-down properly and I traced it to requiring the above additions in<b> bold</b>.  Since I was hooking into power system simulators and third-party graphic libraries it took a wee while to trace :).<br><br></div>The fix above was a bit of guess (the bits in bold) since the PyQt documentation often talks about <i>self</i> being owned by Qt instead of PyQt but I'd seen it in other code so I tried it.  Now I'm more interested to know why so I that I apply this technique in the proper manner.<br><br></div>For example<br><div><br><h3 class=""><a name="QGraphicsScene-3">QGraphicsScene.__init__ (<i>self</i>, float <i>x</i>, float <i>y</i>, float <i>width</i>, float <i>height</i>, </a><a href="http://pyqt.sourceforge.net/Docs/PyQt4/qobject.html">QObject</a> <i>parent</i> = None)</h3><p>***** The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.<<<-----------****</p><p>Constructs a <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qgraphicsscene.html">QGraphicsScene</a>
object, using the rectangle specified by (<i>x</i>, <i>y</i>), and
the given <i>width</i> and <i>height</i> for its scene rectangle.
The <i>parent</i> parameter is passed to <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qobject.html">QObject</a>'s constructor.</p><p></p><p>I'm sure the line "The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt." is probably true but it sure is confusing for a beginner/intermediate programmer. My thinking goes "Is being owned by Qt bad?  My code is using PyQt so I seem to be connecting to another sub system.  If this is not bad, why do I need to know this?. In what context would I need to be aware of this?"<br></p><p>Returning to my example above, <i>without</i> the addition in bold above the line in my code that reads<br></p><p>print("the scene parent is {0}".format(self.parent())) --------------> returns None</p><p><i>With</i> the addition in bold above<br></p><p>print("the scene parent is {0}".format(self.parent())) ---------------->  returns the "scene parent is <sequence_diagrams.SLD_sequence_view object at 0x00000000051648B8>"</p><p>That all seems to make sense.  When the QGraphicsView is destroyed by the QApplication being terminated, the QGraphicsScene is then garbage collected because its parent has died.  Whereas without a parent, the program leave the QGraphicsScene object alive and so the program won't terminate when QApplication finishes.<br></p><p></p><p>Can anyone point me to some documentation that describes what is going on with super and parent=None in the PyQt context, please?  I'd just like to become a bit more comfortable with it.  <br></p><p>Cheers all,</p><p></p><p>Chris O'Halloran<br></p></div></div>