Results 1 to 5 of 5

Thread: QFileSystemModel and custom column / data

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QFileSystemModel and custom column / data

    Quote Originally Posted by d_stranz View Post
    I don't know what you mean by this. Explain what you are trying to accomplish where you think you must "modify item and index values".

    There are two ways to do what you want. First is to derive from your base model (as you have done). The second is to create a proxy model that adds to what the source model provides. I personally prefer to use a proxy rather than derive from the source model. In either case though, you have to pay careful attention to parent-child relationships with model indexes. For selection to work properly, you also have to make sure that mapToSource() and mapFromSource() are correct.


    My apologies, I probably use wrong terms.

    I understood that a Treeview is composed by item, each items is characterized by a row, column.
    When I use the word index, I just want to say a folder or a file in the QFileSystemModel. It could be an "item" in any other environment but it is not the case in Qt so I used "index" to explain my problem. I will do some research on proxy model.

    The easiest way is most likely to have your columns after the ones from the file system model.
    So you can always delegate all requests for column < baseColumnCount to the base class and only handle those above yourself.
    Would you have a short example. I am not sure to understand clearly how to use delegate here.


    Thanks for your helps guys

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

    Default Re: QFileSystemModel and custom column / data

    Quote Originally Posted by ArnSpin View Post
    Would you have a short example. I am not sure to understand clearly how to use delegate here.
    Not a delegate in the model/view concept's sense, but delegating the call.

    Something like:
    Qt Code:
    1. int MyModel::columnCount(const QModelIndex &index) const
    2. {
    3. return QFileSystemModel::columnCount(index) + 2; // two additional columns.
    4. }
    5.  
    6. QVariant data(const QModelIndex &index, int role) const
    7. {
    8. if (index.column() >= QFileSystemModel::columnCount(index)) {
    9. // handle custom columns
    10. } else {
    11. return QFileSystemModel::data(index, role);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Replies: 4
    Last Post: 27th February 2014, 09:42
  2. Adding custom row to QFileSystemModel
    By hiead in forum Qt Programming
    Replies: 2
    Last Post: 12th August 2013, 12:12
  3. QFileSystemModel: creating custom rows of data
    By masterlaws in forum Qt Programming
    Replies: 3
    Last Post: 12th August 2013, 11:58
  4. Replies: 5
    Last Post: 12th December 2012, 18:45
  5. Problem in getting data using QFileSystemModel
    By chinmayapadhi in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2010, 19:34

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
  •  
Qt is a trademark of The Qt Company.