Results 1 to 12 of 12

Thread: QDirModel - add own items

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6

    Default Re: QDirModel - add own items

    ok now i subclassed QDirModel::data and QDirModel::rowCount as following:

    Qt Code:
    1. int MyDirModel::rowCount(const QModelIndex & parent)const
    2. {
    3. if(parent == QModelIndex())
    4. return QDirModel::rowCount(parent) + 1;
    5.  
    6. return QDirModel::rowCount(parent);
    7. }
    8.  
    9. QVariant MyDirModel::data(const QModelIndex & index, int role)const
    10. {
    11. if(index.row() == (QDirModel::rowCount(QModelIndex()) + 1))
    12. {
    13. if(role == Qt::DisplayRole)
    14. return QString(tr("bla"));
    15.  
    16. if(role == Qt::DecorationRole)
    17. return iconProvider()->icon(QFileIconProvider::Desktop);
    18.  
    19. return QVariant();
    20. }
    21.  
    22. return QDirModel::data(index, role);
    23. }
    To copy to clipboard, switch view to plain text mode 

    it does work, however i cannot add an item at the toplevel, only as subentries of other items... I use a treeview to display this, how can i get my item as a toplevel?

    edit: the problem seems to be: rowcount isnt called at toplevel
    edit 2: it is called... why doesnt it show my additional item then ((
    Last edited by heinz32; 11th May 2008 at 17:02.

Similar Threads

  1. Arranging the Items in Qtopia
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 10th December 2007, 08:52
  2. Edit items on QTreeView + QDirModel
    By junior0007 in forum Qt Programming
    Replies: 4
    Last Post: 23rd November 2007, 07:16
  3. Light items for the graphicsView
    By maverick_pol in forum Qt Programming
    Replies: 12
    Last Post: 1st November 2007, 18:51
  4. Replies: 1
    Last Post: 15th March 2007, 20:45
  5. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20

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.