PDA

View Full Version : How to set UserRole within setData for QStandardItem?



neuronet
13th February 2015, 01:30
I am building a tree using QStandardItemModel and populating it with QStandardItems. I am wrapping some data about each item into an object that I then aim to set as the data with role = UserRole. I am presently doing the following:

QStandardItem.setData(object, role = QtCore.Qt.UserRole)
My question is about the documentation for setData(). It says to call setData() with:

QStandardItem.setData(value, role=Qt.UserRole + 1])
I am confused by the "+1".

Since Qt.UserRole = 32, does the +1 mean I should set role to 33? This seems very strange, unless I have multiple different UserRoles to employ, in which case I thought I could start with 32, and go from there. But I don't, I just have one such userRole (for now). Can I use Qt.UserRole, or do I need to start with Qt.UserRole+1?

So far I am just using Qt.UserRole, and it seems to be working ok, but I worry there is some corner case I will hit where the thing will blow up. :eek:

wysota
13th February 2015, 06:42
You can use any number between Qt::UserRole and Qt::MaxUserRole.