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. [solved] programatically expand a particular path in QTreeView
Servers for Qt installer are currently down

[solved] programatically expand a particular path in QTreeView

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.8k 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.
  • O Offline
    O Offline
    ondrejandrej
    wrote on 26 Jan 2015, 18:19 last edited by
    #1

    I have a QTreeView in combination with QFileSystemModel, showing the entire content of my computer (all drives on Windows).
    @m_model = new QFileSystemModel(this);
    m_treeView = new QTreeView(this);
    m_treeView->setModel(m_model);
    m_model->setRootPath(initialPath);@

    I need to show the tree view expanded to initialPath from the beginning. I tried this:
    @m_treeView->expand(m_model->index(initialPath));@

    But it works only when initialPath is one of the drives (like C:). In that case the drive is shown expanded.
    I also tried this, which doesn't seem to work.
    @auto rootIdx = m_model->setRootPath(initialPath);
    m_treeView->selectionModel()->select(rootIdx, QItemSelectionModel::Select);@

    Any idea?

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

      Hi,

      Since the QFileSystemModel loading is threaded, I would rather call expand in a slot connected to "directoryLoaded":http://doc.qt.io/qt-5/qfilesystemmodel.html#directoryLoaded

      Hope it helps

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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 27 Jan 2015, 08:08 last edited by
        #3

        @QTreeView::scrollTo()@
        it also ensures that all parent nodes are expanded

        --- 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
        • O Offline
          O Offline
          ondrejandrej
          wrote on 27 Jan 2015, 09:12 last edited by
          #4

          QTreeView::scrollTo() does the trick!
          directoryLoaded() wasn't helpful.

          1 Reply Last reply
          0

          1/4

          26 Jan 2015, 18:19

          • Login

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