Results 1 to 7 of 7

Thread: Display Filesystem Using QFileSystemModel & QStandardItemModel

  1. #1
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Display Filesystem Using QFileSystemModel & QStandardItemModel

    I had asked the question about displaying Filesystem inside a treeview in such a way where local drives and removable drive get displayed under a root node - Local Drivess & Removable Drives.
    Qt Code:
    1. pSystemPrimaryModel = new QFileSystemModel(this);
    2. pSystemPrimaryModel->setRootPath(QDir::currentPath());
    3. pSystemPrimaryModel->setFilter( QDir::AllDirs | QDir::NoDotAndDotDot );
    4.  
    5. QList<QStandardItem *> LocalItem;
    6. LocalItem.insert(0,new QStandardItem("Local Drives"));
    7. LocalItem.at(0)->setEditable(false);
    8. m_model->insertRow(0,LocalItem);
    9.  
    10. QStandardItem* Localchild = new QStandardItem();
    11. QStandardItem* LocalparentItem = m_model->item(0,0);
    12. LocalparentItem->appendRow(Localchild);
    13.  
    14. ui->PrimTreeView->setModel(m_model);
    To copy to clipboard, switch view to plain text mode 
    This displays output with only Local Drives and no drives under it since I am not setting pSystemPrimaryModel in setModel.
    untitled.JPG
    I wanna display the drives which are shown towards the bottom side of image under this "Local Drives" node which QFileSystemModel displays when used like this:
    Qt Code:
    1. pSystemPrimaryModel = new QFileSystemModel(this);
    2. pSystemPrimaryModel->setRootPath(QDir::currentPath());
    3. ui->PrimTreeView->setModel(pSystemPrimaryModel);
    To copy to clipboard, switch view to plain text mode 
    Last edited by owais_blore; 7th December 2012 at 12:28.

  2. #2
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display Filesystem Using QFileSystemModel & QStandardItemModel

    Anyone here who can help me???

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Display Filesystem Using QFileSystemModel & QStandardItemModel

    And what is the question?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2012
    Location
    Switzerland
    Posts
    32
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display Filesystem Using QFileSystemModel & QStandardItemModel

    If I'm right you want to combine QFileSystemModel and QStandardItemModel in one model and then display it in a treeview?

    Then I'd sugegst using a QAbstractProxyModel, wysota correct me if I'm wrong, haven't dealt with that so much
    Last edited by airglide; 8th December 2012 at 19:05.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Display Filesystem Using QFileSystemModel & QStandardItemModel

    Quote Originally Posted by airglide View Post
    Then I'd sugegst using a QAbstractProxyModel, wysota correct me if I'm wrong, haven't dealt with that so much
    Hard to say. I'm wondering if it's not going to be easier to create a new model from scratch. The problem with proxy models is that it is quite hard to implement a hierarchical proxy model if one is not used to the technology.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display Filesystem Using QFileSystemModel & QStandardItemModel

    Then which is a better approach??? I tried a lot and everytime it seems to just give the same result. I googled a lot and i am surprised nobody has come across this scenario..... what has to be done?

    Quote Originally Posted by wysota View Post
    Hard to say. I'm wondering if it's not going to be easier to create a new model from scratch. The problem with proxy models is that it is quite hard to implement a hierarchical proxy model if one is not used to the technology.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Display Filesystem Using QFileSystemModel & QStandardItemModel

    Quote Originally Posted by owais_blore View Post
    Then which is a better approach??? I tried a lot and everytime it seems to just give the same result. I googled a lot and i am surprised nobody has come across this scenario..... what has to be done?
    To be honest we have no idea what you tried. I'm almost sure there is no "how to add another level of nodes to the filesystem model" tutorial available so you have to go past tutorials and do some thinking of your own. I would probably try some combined approach like having a custom model for the top nodes and attaching filesystem models for the nodes I need. But then I have some quite deep knowledge of how models work in Qt. I think building a model from scratch that is dynamically filled with data using canFetchMore() is also an option. But again this requires something more than just reading one or two tutorials.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    owais_blore (10th December 2012)

Similar Threads

  1. Replies: 0
    Last Post: 20th November 2012, 10:05
  2. Replies: 3
    Last Post: 17th August 2010, 17:58
  3. How to display entire directory(Filesystem)
    By deepakn in forum Newbie
    Replies: 11
    Last Post: 10th November 2009, 09:58
  4. gtk not working in qt filesystem
    By apulu in forum Newbie
    Replies: 11
    Last Post: 18th April 2008, 10:22
  5. Display data from QStandardItemModel in QTreeView
    By jprice01801 in forum Qt Programming
    Replies: 7
    Last Post: 10th January 2007, 09:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.