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. Failing to use QFileSystemModel in Qt
Qt 6.11 is out! See what's new in the release blog

Failing to use QFileSystemModel in Qt

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.3k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I am a newbie in QT. I am working on a app where I need to display the FileSystem using a treeview.

    Basically I have a widget in my .ui file on which I have put a Treeview. Then in my .cpp file I have written the following code:
    @model = new QFileSystemModel(this);
    model->setRootPath(QDir::homePath());
    ui->treeView->setModel(model);@

    In my .h file I have put the following:
    @QFileSystemModel *model;@

    When I run the app, it displays the file system inside the treeview but it also shows Name, Type, Size, DateModified above it. I want to get rid of these.

    How can I achieve it?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @QTreeView::hideColumn@ did the job for me......

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3
        • you mean treeView model base not item based like this
          regard less how many columns you can do this using for

        @{
        ui->setupUi(this);

        // you mean treeView model base not item based like this
        QFileSystemModel *model = new QFileSystemModel(this);
        model->setRootPath(QDir::homePath());
        
        ui->treeView->setModel(model);
        // regard less how many columns you can do this using for:
        for(int i = 1; i < model->columnCount(); i++)
            ui->treeView->hideColumn(i);
        

        }@

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Yes this works well too :)

          [quote author="MuhamedAuda" date="1353055115"]* you mean treeView model base not item based like this
          regard less how many columns you can do this using for

          @{
          ui->setupUi(this);

          // you mean treeView model base not item based like this
          QFileSystemModel *model = new QFileSystemModel(this);
          model->setRootPath(QDir::homePath());
          
          ui->treeView->setModel(model);
          // regard less how many columns you can do this using for:
          for(int i = 1; i < model->columnCount(); i++)
              ui->treeView->hideColumn(i);
          

          }@[/quote]

          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