[PyKDE] QObject.insertChild problems

Austin Clements amdragon at mit.edu
Sat Jul 5 11:40:01 BST 2003


'Lo.  I am implementing a widget that has to layout child widgets in a
particular way (similar to a QVBox, but not quite), so I tried
overriding the insertChild method, but found that the objects passed
to it were always the underlying QObject objects instead of the actual
widgets I added to it.  Here's a simplification of my code and
its output:


import sys
from qt import *

class ComponentStack(QWidget):
    def __init__(self, parent, name="Component stack"):
        QWidget.__init__(self, parent, name)
        self.__vbox = QVBoxLayout(self)

    def insertChild(self, obj):
        print "insertChild(%s)" % `obj`
        QWidget.insertChild(self, obj)
        try:
            self.__vbox.add(obj)
        except AttributeError: pass

app = QApplication(sys.argv)
cs = ComponentStack(None)
app.setMainWidget(cs)
QPushButton("Button", cs)
cs.show()
app.connect(app, SIGNAL('lastWindowClosed()'), app, SLOT('quit()'))
app.exec_loop()


Output:
insertChild(<qt.QObject instance at 0x81e39ac>)
insertChild(<qt.QObject instance at 0x81e49b4>)
Traceback (most recent call last):
  File "bug.py", line 13, in insertChild
    self.vbox.add(obj)
TypeError: Argument 1 of QLayout.add() has an invalid type


The first call occurs in the QWidget constructor, before I've created
the vbox, but the next one, when I add the QPushButton, is the
problem.  Am I doing something wrong, or is there a better way to do
this?

-- 
        __
       /\ \  Austin Clements
      /  \ \  Somewhere in the dream we call reality you will find me,
     / /\ \ \  searching for the reality we call dreams.
    / / /\ \ \
   / / /__\_\ \  http://www.mit.edu/~amdragon
  / / /_______ \  amdragon at mit.edu
 / / ________/\ \  ICQ: 6564732
/ / /        \ \ \  DC2.DwGmL3mW-T-PahltvwSkl,bsCor,eblB-Av++N^
\/_/          \_\/   FM---H+$-R+++!Ac+++U?I--#JS+V+++Q+++Tc+++!E




More information about the PyQt mailing list