Using TreeWidgets
-
Hello-
I'm use to using listView and having trouble with treeWidgets. Is there a way to get the TreeWidget to give you a simple index number like the listView does?
-Thanks
-
Being a hierarchical view, no, there is no such concept as an index here. I wouldn't make sense at all.
Which API call do you refer when talking about "a simple index number"? Maybe there's something similar in the tree view...
-
I can get row numbers from the tree, but that's doesn't really work because they start over when they go into a subtree. So how are you suppose to be able to tell which item is clicked on in these trees if their names aren't unique?
-
The [[Doc:QTreeWidget]] signals contain a QTreeWidgetItem pointer, you can work on that. Isn't that sufficient?
-
Well, if I knew more about the QTreeWidgetItem, it might but as far as I can tell it only holds the a name, but my names are unique, so that causes a problem. How would I tell if I had the write pointer?
-
If you think it helps you, you could use a custom data role on your items and generate a unique ID number that you store in that role. You can then retreive that ID from the item when it is clicked. Reference the setData and data methods in QTreeWidgetItem.
-
Sorry, I don't get the use case. What do you need that index for other than poking the correct item out of the view?
-
I just want to get the correct item out of the tree. Is the only way to use a
@map<QTreeWidgetItem, int>@
or does the treewidget do something like that already for you?
-
If you take the QTreeWidget pointer delivered by the signals, you already HAVE the correct item.
-
[quote author="Arukas" date="1328130428"]I just want to get the correct item out of the tree. Is the only way to use a
@map<QTreeWidgetItem, int>@
or does the treewidget do something like that already for you?
[/quote]
I posted a solution for that just above...