[PyQt] QAbstractItemModel.setData() and emit

Andreas Pakulat apaku at gmx.de
Thu Jul 19 18:41:26 BST 2007

On 19.07.07 09:14:20, Tom Brown wrote:
> On Wednesday 18 July 2007 15:40, Andreas Pakulat wrote:
> > On 18.07.07 14:58:11, Tom Brown wrote:
> > > Hi,
> > >
> > > I am using PyQt4 with Qt 4.2.3. I have subclassed QAbstractItemModel to
> > > create a custom model for a custom combobox. I have overridden the
> > > setData() method and keep getting this error:
> > >
> > > TypeError: invalid result type from ECBModel.setData()
> > >
> > > When I remove the call to emit(), the error goes away. Here is my
> > > setData() method:
> >
> > You don't need to emit dataChanged in setData, you only need to emit
> > that signal if you change data in custom methods.
> The documentation says you need to emit dataChanged() if you reimplement the 
> setData() method.
> "Note that the dataChanged() signal must be emitted explicitly when 
> reimplementing this function."

Hmm, my Qt4.3 docs only say it should be emitted, not that it has to be
emitted. Anyway, basically you're right and I was wrong (looks like my
last model impl. is quite some time ago)

> > Also note: setData shouldn't alter the number of rows or columns in the
> > model, it should only change the data of an existing "cell". If you want
> > to add a row/column you should use insertRows/Columns (and eventually
> > re-implement them).
> Well, I reimplemented a few required methods like index() and parent(). The 
> error stopped showing up. However, the combobox never shows a value even 
> though there are items in the list. Any ideas on that?

Not without some example code. Up-to-date PyQt snapshots contain a
python port of the ModelTest from Qt Labs, it can be used to test wether
your model conforms to the assumptions that views make about it.


You have a deep interest in all that is artistic.

More information about the PyQt mailing list