PDA

View Full Version : QAbstractItemDelegate editing behavior confusion



t_3
24th June 2015, 14:39
referring to Qt4.8... i'm utterly confused about what the docs say how a custom delegate editor shold work and what i observe instead.

my requirements: a custom line editor that only submits its value to the model on particular user action, but not i.e. just on focus out. i of course have all i need to accomplish that, so i only need to wrap the delegate around my custom line editor in a way it fits my needs, but...

the docs say in particular:
qabstractitemdelegate.html#setModelData

Sets the data for the item at the given index in the model to the contents of the given editor.

The base implementation does nothing. If you want custom editing you will need to reimplement this function.

and for qabstractitemdelegate.html#commitData

This signal must be emitted when the editor widget has completed editing the data, and wants to write it back into the model.

i admit, english is not my native language, but for me this means that if i don't reimplement setModelData and don't explicitly send commitData in my custom delegate, then nothing will ever happen to the underlying model, no matter what the editor does.

in my case*) this isn't true. if i create my line editor widget in createEditor(...) and do nothing of the above, the base class still magically updates the model data to the last line editor value as soon the editor is destroyed (what i explicitly wanted to avoid)

*) note: i write a plugin for a host that _might_ use modified Qt sources, so i'm really keen to know if the behavior i doubtlessly observe here is Qt standard and just the docs are completely misleading, or if some other strange things are going on...

anda_skoa
24th June 2015, 16:51
And your delegate derives directly from QAbstractItemDelegate?

Because its setModelData() does indeed not do anything: http://code.woboq.org/kde/qt4/src/gui/itemviews/qabstractitemdelegate.cpp.html#_ZNK21QAbstractItem Delegate12setModelDataEP7QWidgetP18QAbstractItemMo delRK11QModelIndex

Cheers,
_

t_3
24th June 2015, 19:28
AH :o

thanks for the "pointer"!

... too much inheritance, to much night hours. in fact there is a QItemDelegate somewhere down the road, and all the editor factory stuff takes place.
gruß aus wien ;)