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. Using TreeWidgets
Qt 6.11 is out! See what's new in the release blog

Using TreeWidgets

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.7k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Arukas
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

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

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Arukas
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          The [[Doc:QTreeWidget]] signals contain a QTreeWidgetItem pointer, you can work on that. Isn't that sufficient?

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Arukas
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                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?

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Arukas
                  wrote on last edited by
                  #8

                  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?

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    If you take the QTreeWidget pointer delivered by the signals, you already HAVE the correct item.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

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

                      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