Results 1 to 9 of 9

Thread: Custom file system implementation in Qt

  1. #1
    Join Date
    Apr 2016
    Posts
    5
    Qt products
    Qt5

    Default Custom file system implementation in Qt

    I am researching a way of implementing a simple file system UI. The requirement is that I have an in-memory tree (custom data structure), similar to a file system. But this is not the real file system of the computer. So, I want to represent this internal implementation to the user to react with that like adding new files, deleting files, editing files, adding folders, i.e. the basic operations.

    I have no idea how to achieve this using Qt UIs. Is that a good idea to represent these files/folders using QLabel and setting pixmap for them? If I implement it like this, it is lot of work, like, once the folder is clicked, the frame should be cleared and the new set of labels should be loaded in the same frame.

    What will be the easiest way?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,073
    Thanks
    233
    Thanked 649 Times in 639 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Custom file system implementation in Qt

    Why don't you create a QAbstractItemModel to represent your internal tree structure, and then use a QTreeView to display it on screen? This is basically what QFileSystemModel does with the real file system.

    QAbstractItemModel allows you to have an icon for each entry. When you implement the QAbstractItemModel::data() you just need to return the right thing for each of the Qt Roles. If you want to allow the user to change the model by interacting with the view, that's more work, and you'll have to implement the QAbstractItemModel::setData() method to do that.

    There is a pretty good Qt example on implementing an editable tree model. I am not sure if it implements support for drag and drop to rearrange the tree, but you should be able to implement that once you have the basic model working.

  3. #3
    Join Date
    Apr 2016
    Posts
    5
    Qt products
    Qt5

    Default Re: Custom file system implementation in Qt

    thanks I'll try it

  4. #4
    Join Date
    Apr 2016
    Posts
    5
    Qt products
    Qt5

    Default Re: Custom file system implementation in Qt

    Can I know without having a tree model, is there a way to create a normal file-system-like interface like windows file-explorer or linux file-explorer with icon and double click on it?

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom file system implementation in Qt

    QListView in IconMode, with a list model that operates on one "directory"

    Cheers,
    _

  6. #6
    Join Date
    Apr 2016
    Posts
    5
    Qt products
    Qt5

    Default Re: Custom file system implementation in Qt

    Can you please send me an example or a code snippet for more understanding?

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,073
    Thanks
    233
    Thanked 649 Times in 639 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Custom file system implementation in Qt

    Can you please send me an example or a code snippet for more understanding?
    If your "file system" is a hierarchy (that is, an item can have a parent as well as children), then a tree model is probably the best way to implement this, unless you only show one level at a time. That is, as anda_skoa suggested, your view consists of a simple list of the items at that level of the hierarchy, and you use some other way to move up or down.

    In the old Windows FileManager program, the right side window displayed only a single level of the file system. To navigate to a lower level, you could double-click a directory entry; to go up a level, you double-clicked the ".." entry. The left side tree view was unnecessary for navigation.

    You could derive a class from QStringListModel to represent the items at one level of your hierarchy. The only function you would have to reimplement is the data() method, and in that, the only thing you need to add is a case to handle the Qt::DecorationRole to return the icon for that entry. Everything else can be handled by the QStringListModel::data() implementation.

    Google is your friend. There are many examples of how to use QListView, QStringListModel, and Qt::ItemDataRole.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom file system implementation in Qt

    Quote Originally Posted by d_stranz View Post
    You could derive a class from QStringListModel to represent the items at one level of your hierarchy.
    I would not start with a QStringListModel.
    ayash mentioned icon, maybe even wants things like size, etc. so a custom list model or QStandardItemModel should provide a better start.

    Cheers,
    _

  9. #9
    Join Date
    Apr 2016
    Posts
    5
    Qt products
    Qt5

    Default Re: Custom file system implementation in Qt

    I would not start with a QStringListModel.
    ayash mentioned icon, maybe even wants things like size, etc. so a custom list model or QStandardItemModel should provide a better start.
    Yes, I need "set of icons" in my explorer. When I double click on the directory icon, it should go into that directory and if I double click on a file it should trigger a custom event a user can define it, likewise. Better if you can kindly provide me an example as I requested

Similar Threads

  1. Custom Select implementation
    By joko in forum Qt Quick
    Replies: 1
    Last Post: 5th November 2015, 15:58
  2. Replies: 7
    Last Post: 27th February 2014, 22:11
  3. Custom SelectionModel implementation needed?
    By graffy in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2014, 04:47
  4. Replies: 1
    Last Post: 7th May 2013, 00:34
  5. QImageReader with custom QIODevice implementation
    By psih128 in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2011, 03:39

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.