[PySide] model/view: faster to access a user role than accessing a dict?

Frank Rueter frank at ohufx.com
Mon Oct 3 09:22:53 CEST 2022


Hi all,

I am building a model for a tree view and have a dictionary that represents
all the data in the required hierarchy.
I have to be able to filter the view, select things programmatically and
show info based on selected items etc.
I am wondering:
With all required data per item available in a dict, is it more efficient
to just stuff that into the item's UserRole data or to create custom user
roles for each value in the dict that I will be filtering/sorting by or
looking up for some other reason?
E.g.:
Will there be a difference in performance with this:
   item = QStandardItem()
   item.setData(my_dict, UserRole)
   then:
   item.data(UserRole)["typeA"]
   item.data(UserRole)["typeB"]
   item.data(UserRole)["typeC"]

compared to this approach?:
   item = QStandardItem()
   item.setData(my_dict["dataA"], UserRole)
   item.setData(my_dict["dataB"], UserRole+1)
   item.setData(my_dict["dataC"], UserRole+2)
   then:
   item.data(UserRole)
   item.data(UserRole+1)
   item.data(UserRole+2)


Cheers,
frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20221003/3c39e3f9/attachment.htm>


More information about the PySide mailing list