[PyQt] Adding a widget to a layout that belongs to a QGroupBox
changes that widget's parent?
Nate Reid
nreid at imagemoversdigital.com
Thu Aug 13 23:34:44 BST 2009
I'm using PyQt 4.5.1
For some reason the parent is changing, but only when a QGroupBox is used...
Another odd thing is that if I uncomment out the line "self.layout.addWidget(self.box), it crashes (e.g. stalls out completely, and I have to kill the shell)
Here is the sample script that produces the issue:
#################
import sys
from PyQt4 import QtCore, QtGui
class MyWidget(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.box = QtGui.QGroupBox()
self.tree = QtGui.QTreeWidget(self)
print "Tree's parent before being layed out:", self.tree.parent()
self.layout = QtGui.QVBoxLayout()
self.layout.addWidget(self.tree)
self.box.setLayout(self.layout)
print "Tree's parent after being layed out:", self.tree.parent()
self.othertree = QtGui.QTreeWidget(self)
print "Other Tree's parent before being layed out:", self.othertree.parent()
self.otherlayout = QtGui.QVBoxLayout()
self.otherlayout.addWidget(self.othertree)
self.setLayout(self.otherlayout)
print "Other Tree's after before being layed out:", self.othertree.parent()
# self.layout.addWidget(self.box)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
widget = MyWidget(None)
widget.show()
sys.exit(app.exec_())
#################
Thanks!
-Nate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090813/92b4c364/attachment-0001.html
More information about the PyQt
mailing list