[PyQt] Adding methods to C++-created objects

Giovanni Bajo rasky at develer.com
Wed Oct 17 23:00:03 BST 2007


On Wed, 2007-10-17 at 18:18 +0100, Phil Thompson wrote:

> > class MyDelegate(QItemDelegate):
> >      def createEditor(self, *args):
> >          ed = QItemDelegate.createEditor(self, *args)
> >          ed.foo = bar  # adding stuff to python instance
> >          ed.foo2 = lambda: bar
> >          return ed
> >
> >      def setModelData(self, editor, model, index):
> >          print editor.foo   # accessing python stuff added before
> >
> >
> > I think it's either a PyQt bug or simply this usage pattern is not fully
> > supported. If this is something that should work, I'll work on a repro
> > recipe.
> 
> It should work (assuming the parent argument to createEditor() is not 
> None/NULL).
> 
> The qitemdelegate.sip file looks like it might be missing some annotations. 
> The following may help...
> 
>   virtual QWidget *createEditor(QWidget *parent /TransferThis/,
>       ...) const /Factory/;

This fixed it, thanks!
-- 
Giovanni Bajo




More information about the PyQt mailing list