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] QFileSystemModel root path
Forum Updated to NodeBB v4.3 + New Features

[Solved] QFileSystemModel root path

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 9.4k 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.
  • S Offline
    S Offline
    szh1
    wrote on last edited by
    #1

    It says in the documentation that QFileSystemModel::setRootPath does not set the root path that is visible in the tree view. Is there a way to set the real root path, so that no directories above it are visible?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tony
      wrote on last edited by
      #2

      Hi,

      well, you're right, the documentation is a bit confusing. In the class description, it says:

      QFileSystemModel will not fetch any files or directories until setRootPath is called. This will prevent any unnecessary querying on the file system until that point such as listing the drives on Windows.

      ... but later, in setRootPath, it reports what you say.

      I didn't verify this by myself ... in any case, if it's true that the model cannot hide directories that are above a specific point, you should use a QSortFilterProxyModel attached to it, and filter out the directories you don't need (i.e., those that don't have the root path equal to the one you specify).

      T.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dfaure
        wrote on last edited by
        #3

        You mean, given /a/b, /a/c and /a/d, you want to set "/a/b/" as root path, and the model should show an item for "b" but not for "a" and "c"? I don't believe this is possible out of the box, you would have to use a QSortFilterProxyModel indeed (and reimplement filterAcceptsRow).

        David Faure (david.faure@kdab.com)
        KDE/Qt Senior Software Engineer
        KDAB - Qt Experts - Platform-independent software solutions

        1 Reply Last reply
        0
        • E Offline
          E Offline
          endhck
          wrote on last edited by
          #4

          Hi, I want to do same thing, I guess.

          I want to give the root folder to the program, and the tree should show the root and the sub folders.

          @QTreeView *treeView = new QTreeView;
          QFileSystemModel *sourceModel = new QFileSystemModel();
          QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel();

          proxyModel->setSourceModel(sourceModel);
          *proxyModel->setFilterRegExp(QRegExp("C:", Qt::CaseInsensitive,QRegExp::FixedString));
          proxyModel->setFilterKeyColumn(0);
          treeView->setModel(proxyModel);

          treeView->resize(640, 480);
          treeView->show();@

          I did like this, but it returns me nothing.
          How can I fix this?

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

            As stated above and in the docs:
            [quote]QFileSystemModel will not fetch any files or directories until setRootPath is called. This will prevent any unnecessary querying on the file system until that point such as listing the drives on Windows.[/quote]

            As for starting off at a certain node, would setRootIndex do the trick? You can retreive the index to use as root by using QFileSystemModels methods to get a QModelIndex for a path.

            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