[PySide] calling item.setData multiple times from inside QItemDelegate.setModelData

Frank Rueter | OHUfx frank at ohufx.com
Mon Sep 19 07:04:26 CEST 2016


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>* *

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160919/d2d1effc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ohufxLogo_50x50.png
Type: image/png
Size: 2666 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160919/d2d1effc/attachment.png>


More information about the PySide mailing list