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. Dynamically select TreeView item.

Dynamically select TreeView item.

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 906 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.
  • D Offline
    D Offline
    dayobject
    wrote on 22 Dec 2015, 19:59 last edited by
    #1

    I have a signal/slot hooked up to return an object that exists within my treeview model.

    My question is, how can I find the particular item in the tree view based on this model data? Do I need to traverse the entire tree structure to find a match?

    Does something like below exist?

    QModelIndex indexOfTreeItem = m_pCurrentModel->findIndex(modelData);

    Thanks.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Dec 2015, 21:59 last edited by
      #2

      Hi and welcome to devnet,

      Are you using a custom model ? If so, it's up to you to provide the findIndex method for your model.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply 23 Dec 2015, 14:29
      0
      • R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 23 Dec 2015, 08:02 last edited by raven-worx
        #3

        probably the best would be to store the object in a hash-table for quick lookup.
        But make sure to cleanup the hash table once the object is destroyed to avoid dumping the memory.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • S SGaist
          22 Dec 2015, 21:59

          Hi and welcome to devnet,

          Are you using a custom model ? If so, it's up to you to provide the findIndex method for your model.

          D Offline
          D Offline
          dayobject
          wrote on 23 Dec 2015, 14:29 last edited by
          #4

          @SGaist Thanks. I'm not using a custom model, though it's looking like I might need to write a custom method to find the value.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 23 Dec 2015, 14:58 last edited by
            #5

            about how many tree items are we talking here?
            Is the model static or dynamic (items added/removed during runtime)?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0

            1/5

            22 Dec 2015, 19:59

            • Login

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