Results 1 to 3 of 3

Thread: Adding custom row to QFileSystemModel

Hybrid View

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

    Default Re: Adding custom row to QFileSystemModel

    Quote Originally Posted by hiead View Post
    My issue is I'm not entirely sure how to add a separate branch to the end of the QFileSystemModel. I understand that I should use a proxy model, and set its source to my QFileSystemModel subclass.
    Well, since you already have a QFileSystemModel subclass, you could also implement that in there.
    Has the advantage that you can use QModelIndex instances of the base class as-is and only need to provide new ones for your additional data. In a proxy you always need to map between source model indexes and your own.

    Quote Originally Posted by hiead View Post
    So far I know I need to override rowCount() (to return sourceModel's rowCount+1 from the root node, and # of rows within the branch). I know I would have to override index() to return an index for each extra item, and obviously data(), but this is what gets me, as I don't know exactly how to work the rest. I'm also not sure how to handle the fact that a QFileSystemModel's data is prone to random change in row counts as files are added and deleted.
    Every model has signals that are emitted before and after such changes as rows being added, etc. This is how the view knows when to update itself.

    In case of using a proxy model you would connect to the source model's signals, usually in an overwritten implementation of setSourceModel().

    If you go for adding your data inside your QFileSystemModel subclass, then you most likely don't have to do that, because your data is always "after" the base class data.
    So all signals will have proper row values already and whenever rowCount() is called for the top level it is always that of the base class plus your entry.

    Cheers,
    _

  2. #2
    Join Date
    Jun 2013
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    2

    Default Re: Adding custom row to QFileSystemModel

    Hi Hiead, I also want similar functionality, please let me know if you got solution for this problem. Thanks

Similar Threads

  1. QFileSystemModel: creating custom rows of data
    By masterlaws in forum Qt Programming
    Replies: 3
    Last Post: 12th August 2013, 11:58
  2. Replies: 5
    Last Post: 12th December 2012, 18:45
  3. Custom QGraphicsItem - Adding a QListWidget
    By El Bazza in forum Qt Programming
    Replies: 8
    Last Post: 12th September 2012, 16:19
  4. adding files to QFileSystemModel
    By gluchu in forum Newbie
    Replies: 1
    Last Post: 11th July 2012, 00:25
  5. Adding Custom Widgets to the QT Designer
    By Polnareff in forum Qt Programming
    Replies: 1
    Last Post: 17th May 2010, 21:31

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