Items in TreeView
-
I was able to insert items into the treeview.
How do I access the individual items in the treeview model?
Also is there any way to fill the values in a form from a xml file based on what values are selected in the tree view?For example if Smiles is clicked in the list, the values related to smiles in the xml file should be filled in the dialog UI.
-
I was able to insert items into the treeview.
How do I access the individual items in the treeview model?
Also is there any way to fill the values in a form from a xml file based on what values are selected in the tree view?For example if Smiles is clicked in the list, the values related to smiles in the xml file should be filled in the dialog UI.
How do I access the individual items in the treeview model?
In any model, including that used for a
QTreeView
, you access data viadata(const QModelIndex &index)
. In the case of hierarchical model used for aQTreeView
the indexes will have aparent()
index which needs to be specified appropriately. Dedicated "items" only really applies to aQTreeWidget
, which wraps data inQTreeWidgetItem
s.Also is there any way to fill the values in a form from a xml file based on what values are selected in the tree view?
For example if Smiles is clicked in the list, the values related to smiles in the xml file should be filled in the dialog UI.If you used an XML file to create your model/treeview (is that what you mean?) it is your job to find the XML node corresponding to a treeview item. Unless you stored the XML into a model role for each index or used a model directly off the XML, such as
QDomDocument
. -
@JonB said in Items in TreeView:
If you used an XML file to create your model/treeview (is that what you mean?) it is your job to find the XML node corresponding to a treeview item. Unless you stored the XML into a model role for each index or used a model directly off the XML, such as
QDomDocument
.Yes I used an XML File to create the TreeView. In that treeview the values corresponding to the name tags are present in the treeview as items.
So I should iterate through the XML file and compare and see if the selected item matches any in the XML file and then I should print all the values corresponding to the same in the UI?
-
@JonB said in Items in TreeView:
If you used an XML file to create your model/treeview (is that what you mean?) it is your job to find the XML node corresponding to a treeview item. Unless you stored the XML into a model role for each index or used a model directly off the XML, such as
QDomDocument
.Yes I used an XML File to create the TreeView. In that treeview the values corresponding to the name tags are present in the treeview as items.
So I should iterate through the XML file and compare and see if the selected item matches any in the XML file and then I should print all the values corresponding to the same in the UI?
@QtisHard said in Items in TreeView:
Yes I used an XML File to create the TreeView.
In what sense? You don't "create" a
QTreeView
, you create the model it is bound to. You would have to find what model item is selected and then find the node that came from in the XML.So I should iterate through the XML file and compare and see if the selected item matches any in the XML file
Re-reading could be slow if it is a large XML file. And "matches any" is not very exact, you could have multiple matches for all I know. Depends on your XML.
-
Apologies @JonB
I create a model and bind it to the treeview.
So I have to see what item is selected in the treeview and then compare all the values in the xml file to see which one it is.I need to compare with the name tags in the XML and all Names in the XML file are unique.
However the XML file is very large ( Over 30000 lines of code)
Is there any other method that you would suggest? -
Apologies @JonB
I create a model and bind it to the treeview.
So I have to see what item is selected in the treeview and then compare all the values in the xml file to see which one it is.I need to compare with the name tags in the XML and all Names in the XML file are unique.
However the XML file is very large ( Over 30000 lines of code)
Is there any other method that you would suggest?@QtisHard
I (think I) have said. If you want to be efficient with 30,000 lines of XML you ought to make your model aQDomDocument
. You'd have to write that. Otherwise if you know the structure and it's simple, read in all the information and make it accessible via dedicated data structures for look up in your model. Maybe aQTreeWidget
would be OK to use, maybe you should try that first. If you don't care about efficiency you can re-read the XML file every time, these days maybe dealing with 30k of lines is really quick, you will see when you try it.