Hi all,
I'm using a QStandardItemModel with QItemDelegate for a custom view
where I need to set multiple values for one item when the editor closes.
I had these lines in my delegate's setModelData() method:
item.setData(editor.player.isMirroredX , EL.MirrorXRole)
item.setData(editor.player.isMirroredY , EL.MirrorYRole)
item.setData(editor.player.currentFrameNumber() ,
EL.CurrentFrameRole)
This led to inconsistent and unpredictable results though, e.g. often
times the editor.player.currentFrameNumber() was not saved, or it was
only saved when one of the other values changed as well.
I had a hunch that the repeated emission of dataChanged was teh culprit,
so blocked the model's signals before running the above three lines,
then re-enabled the signals and manually emitted model.dataChanged once:
# temporarily block model signals to prevent multiple emissions of
# the dataChanged signal which causes unpredictable results
item.model().blockSignals(True)
# set values for allnecessary roles
item.setData(editor.player.isMirroredX , EL.MirrorXRole)
item.setData(editor.player.isMirroredY , EL.MirrorYRole)
item.setData(editor.player.currentFrameNumber() ,
EL.CurrentFrameRole)
# re-enable model's signla emissions
item.model().blockSignals(False)
# manually emit dataChanged once now that all roles have been
changed
item.model().dataChanged.emit(index, index)
This seems somewhat hacky though, right? Is there a better way that
people would recommend to set the value for multiple roles of the same
index/item in one go inside the setModelData?
Or is the above legit?
Cheers,
frank
--
ohufxLogo 50x50 <http://www.ohufx.com> *vfx compositing
<http://ohufx.com/index.php/vfx-compositing> | *workflow customisation
and consulting <http://ohufx.com/index.php/vfx-customising>* *
_______________________________________________
PySide mailing list
PySide@qt-project.org
http://lists.qt-project.org/mailman/listinfo/pyside