Results 1 to 5 of 5

Thread: QDirModel lowlevel acces to model items for add it

  1. #1
    Join Date
    Oct 2010
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question QDirModel lowlevel acces to model items for add it

    I use QTreeView + QDirModel, for view my catalog. My catalog have one file 'File1.txt'. But I need display second file ‘File2.txt’ in QTreeView but don’t create this file in my catalog!.
    File2.txt have been to QDirModel and display in QTreeView but not create physically on my drive when be located my catalog i.e. I`am not use Filters.


    MyCatalog
    -- File1.txt - Realy file in my catalog
    -- File2.txt - Only display file in QTreeView!



    I create class with reimplemented method “insertRow()”:

    Qt Code:
    1. class DirModelMod : public QDirModel
    2. {
    3.  
    4. public:
    5. DirModelMod();
    6. ~DirModelMod();
    7.  
    8. private:
    9. bool insertRow ( int row, const QModelIndex & parent = QModelIndex() );
    10.  
    11. };
    To copy to clipboard, switch view to plain text mode 


    But how I`am can add item (files) in insertRow()?
    Please litle sample how add item in QDirModel in reimplement insertRow() or what I need using. And then for setData() I`am understand myself. Tnks.


    PS I`am not insert ‘File2.txt’ in QTreeView because it created in QT Designer and file must view in other widgets.
    PS Sr for my English
    Last edited by Jarikus; 25th October 2010 at 21:06.

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

    Default Re: QDirModel lowlevel acces to model items for add it

    Try describing your problem again in some simpler words and proper sentences. It is hard to understand what you have, what you need and what doesn't work.
    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.


  3. #3
    Join Date
    Oct 2010
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDirModel lowlevel acces to model items for add it

    Try describing your problem again in some simpler words and proper sentences. It is hard to understand what you have, what you need and what doesn't work.
    I have catalog where only one file:


    My program display it via QTreeView + QDirModel:


    But I need display second file in QTreeView without creation this file:



    I think modification method insertRow () and then manually add it:

    Qt Code:
    1. insertRow( 1, rootIndex );
    2. setData( this->index( 1, 0, rootIndex), QVariant("N:/File2.txt"), FilePathRole);
    3. setData( this->index( 1, 0, rootIndex), QVariant("File2.txt"), FileNameRole);
    To copy to clipboard, switch view to plain text mode 

    But I`am don’t know how modification method:

    Qt Code:
    1. bool insertRow ()
    2. {
    3. ……
    4. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Jarikus; 25th October 2010 at 21:38.

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

    Default Re: QDirModel lowlevel acces to model items for add it

    Either subclass the model and reimplement rowCount() and data() to return the additional item or use a proxy model wrapping the base model and add the artificial item there. Touching insertRow (or rather insertRows) from the dir model is not a good idea.
    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.


  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDirModel lowlevel acces to model items for add it

    Depending on how much of QDirModel you are using, you may even find that it's worthwhile creating your own model based on QAbstractItemModel and using QDirIterator, but that is a little like using a sledgehammer to crack a nut It depends on what your design shows for future versions of your class.

Similar Threads

  1. QDirModel - add own items
    By heinz32 in forum Newbie
    Replies: 11
    Last Post: 15th May 2008, 11:23
  2. Edit items on QTreeView + QDirModel
    By junior0007 in forum Qt Programming
    Replies: 4
    Last Post: 23rd November 2007, 07:16
  3. QDirModel+QTreeView and checkable items
    By L.Marvell in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2007, 18:54
  4. Replies: 1
    Last Post: 15th March 2007, 20:45
  5. QDirModel, Model/View, extend the file onfo
    By VlJE in forum Qt Programming
    Replies: 10
    Last Post: 11th December 2006, 10:56

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.