Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Items in TreeView
QtWS25 Last Chance

Items in TreeView

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 396 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QtisHard
    wrote on last edited by
    #1

    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?

    8b94bf3d-84a6-44bc-a221-beea013ec617-image.png

    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.

    JonBJ 1 Reply Last reply
    0
    • Q QtisHard

      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?

      8b94bf3d-84a6-44bc-a221-beea013ec617-image.png

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @QtisHard

      How do I access the individual items in the treeview model?

      In any model, including that used for a QTreeView, you access data via data(const QModelIndex &index). In the case of hierarchical model used for a QTreeView the indexes will have a parent() index which needs to be specified appropriately. Dedicated "items" only really applies to a QTreeWidget, which wraps data in QTreeWidgetItems.

      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.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        QtisHard
        wrote on last edited by
        #3

        @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?

        JonBJ 1 Reply Last reply
        0
        • Q QtisHard

          @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?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          1
          • Q Offline
            Q Offline
            QtisHard
            wrote on last edited by
            #5

            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?

            JonBJ 1 Reply Last reply
            0
            • Q QtisHard

              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?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @QtisHard
              I (think I) have said. If you want to be efficient with 30,000 lines of XML you ought to make your model a QDomDocument. 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 a QTreeWidget 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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved