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. how to find a qtreewidgetitem by a member variable??

how to find a qtreewidgetitem by a member variable??

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 752 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.
  • A Offline
    A Offline
    abdullahzubair109
    wrote on last edited by
    #1

    i have created a qtreewidget for showing folders using custom qtreewidgetitem.. for each custom qtreewidgetitem, i have set a member variable to store directory path.. now i want to find these items by directory path variable, not by text as QTreeWidget::findItems() provides.. how can i implement such feature??

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You have to walk the complete tree with the help of QTreeWidget::topLevelItemCount/topLevelItem and the QTreeWidgetItem::childCount/child functions

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        You have to walk the complete tree with the help of QTreeWidget::topLevelItemCount/topLevelItem and the QTreeWidgetItem::childCount/child functions

        A Offline
        A Offline
        abdullahzubair109
        wrote on last edited by
        #3

        @Christian-Ehrlicher that's kinda brute force approach.. ok, i will try.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          abdullahzubair109
          wrote on last edited by
          #4

          i used 2 vectors to hold path variables and treewidgetitem pointers seperately.. now i am finding the index of path from path variables and calling respective treewidgetitem.. it is solved.

          mrjjM 1 Reply Last reply
          0
          • A abdullahzubair109

            i used 2 vectors to hold path variables and treewidgetitem pointers seperately.. now i am finding the index of path from path variables and calling respective treewidgetitem.. it is solved.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @abdullahzubair109
            Hi
            I wondered why you needed to vectors?
            Would a std::map not have been easier ?
            std::map<QString, QTreeWidgetItem *> lookup;

            A 1 Reply Last reply
            2
            • mrjjM mrjj

              @abdullahzubair109
              Hi
              I wondered why you needed to vectors?
              Would a std::map not have been easier ?
              std::map<QString, QTreeWidgetItem *> lookup;

              A Offline
              A Offline
              abdullahzubair109
              wrote on last edited by
              #6

              @mrjj thanks for the suggestion. map is better

              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