I'm currently working on an update to an old application I made ages ago and as part of the update I want to scrap whatever Microsoft GUI system I was using before and instead use Qt which seems MUCH more functional. I managed to work out how to get the QTreeWidget to behave the way I want, but I'm really struggling to figure out where the data is and how it's stored. I can follow the basic hierarchical structure of the rows and columns no problem but I can't seem to find any of the data that I filled out in the Qt Designer
.
Following a few scraps of info I was able to find I tried to get the data for the second column of the first row of the first parent row like this:
ui.treeWidget->topLevelItem(0)->child(0)->data(1, Qt::UserRole)
ui.treeWidget->topLevelItem(0)->child(0)->data(1, Qt::UserRole)
To copy to clipboard, switch view to plain text mode
But it keeps saying the QVariant is an invalid type and I cant figure out why, the data should be an integer or at least text because it still displays correctly.
Ultimately the way I want to use the QTreeWidget is that rather than fill it with the Qt Designer I want to populate it from a database, there will be several collapsible categories that each have a list of data fields and their numerical value, the first column will be an uneditable label for the data field and the second column will be an editable integer that will need to be saved back into the database at some point. As I said I got the behavior working great, the label is uneditable and the value can be edited and is limited to numeric values, but I just can't figure out how to get the data.
Can anyone help me with how to get the data? Also if there's a better way to do things for the way I plan for it to be used I'd love to hear about it.
Bookmarks