Alternatively, you can store the ID as Qt::UserRole data for the model index: QAbstractItemModel::setData(). When you get notified of the selected index, you ask it for the UserRole data, which is returned as a QVariant.
Alternatively, you can store the ID as Qt::UserRole data for the model index: QAbstractItemModel::setData(). When you get notified of the selected index, you ask it for the UserRole data, which is returned as a QVariant.
Oh, I tried to do what you described.. It works only while my column is visible...
hm... I'll try it, thanks!
Are you using a proxy model to convert the DB result into something to display in the tree?
I am creating QStandardItem and recursively appending rows..
child_node = QtGui.QStandardItem("ITEM TEXT")
root.appendRow(child_node)
"ITEM TEXT" - is getting directly from sqlite...for each iteration...
Well then it is easy - when you create the QStandardItem, just callWhen you get the selected item, then it is justQt Code:
To copy to clipboard, switch view to plain text mode(or whatever the appropriate syntax is - I'm not a python programmer).Qt Code:
ID = selected_node.data( Qt::UserRole )To copy to clipboard, switch view to plain text mode
serj (4th April 2015)
It works! Thanks! This is exactly what I need..
child_node.setData(QtCore.QVariant(str(chld["ID"]))) #setting data
selected_id = str(index.model().itemFromIndex(index).data().toSt ring()) #getting data
Bookmarks