Results 1 to 14 of 14

Thread: Creating a QAbstractItemModel for QTreeView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Creating a QAbstractItemModel for QTreeView

    hi
    Qt Code:
    1. MyDirModel:: MyDirModel(QObject *parent)
    2. : QDirModel(parent)
    3. {
    4. removeColumn(QDirModel::columnCount() - 1);
    5. }
    6.  
    7.  
    8. MyDirModel::~MyDirModel()
    9. {
    10. }
    11.  
    12.  
    13. int MyDirModel::columnCount(const QModelIndex& parent) const
    14. {
    15. return QDirModel::columnCount(parent) + 2 ;
    16. }
    17.  
    18. QVariant MyDirModel::data(const QModelIndex & index, int role) const
    19. {
    20. if( role==Qt::DisplayRole )
    21. {
    22. if( index.column()==QDirModel::columnCount() )
    23. return fileInfo( index ).owner();
    24. else
    25. if( index.column()==QDirModel::columnCount() +1 )
    26. return fileInfo( index ).group();
    27. }
    28. return QDirModel::data(index, role);
    29. }
    To copy to clipboard, switch view to plain text mode 
    the column "last modified" was not removed and the new columns are empty
    Last edited by hbill; 30th March 2008 at 13:41.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Creating a QAbstractItemModel for QTreeView

    QDirModel does not implement QAbstractItemModel::removeColums() so you can't use it. Either hide it from the view or make the subclass return alternative data for that particular column. Start with checking out if anything shows up in those columns when you return a fixed test string. After that, continue with investigating whether the QFileInfo returned by fileInfo() is ok.
    J-P Nurmi

  3. #3
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Creating a QAbstractItemModel for QTreeView

    hi

    Qt Code:
    1. QVariant MyDirModel::data(const QModelIndex & index, int role) const
    2. {
    3. QMessageBox msgBox;
    4. //msgBox.exec();//ok
    5. if( role==Qt::DisplayRole )
    6. {
    7. //msgBox.exec();//ok
    8. if( index.column()==QDirModel::columnCount() )//problem
    9. {
    10. //msgBox.exec();//not ok
    11. return fileInfo( index ).owner();
    12. }
    13. else
    14. if( index.column()==QDirModel::columnCount() +1 )//problem
    15. return fileInfo( index ).group();
    16. else
    17. if( index.column()==QDirModel::columnCount() -1 )
    18. {
    19. //msgBox.exec();//ok
    20. return fileInfo( index ).owner();//ok
    21. }
    22. }
    23. return QDirModel::data(index, role);
    24. }
    To copy to clipboard, switch view to plain text mode 
    i have a problem with the new columns !!!

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Creating a QAbstractItemModel for QTreeView

    Quote Originally Posted by hbill View Post
    i have a problem with the new columns !!!
    Could you be a bit more verbose about the problem, please?
    J-P Nurmi

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

    Default Re: Creating a QAbstractItemModel for QTreeView

    Quote Originally Posted by jpn View Post
    Could you be a bit more verbose about the problem, please?
    Yeah... a more verbose version is "they are not working!"

    Sorry, couldn't resist myself...

  6. #6
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Creating a QAbstractItemModel for QTreeView

    the test
    Qt Code:
    1. if( index.column()==id_column )
    To copy to clipboard, switch view to plain text mode 
    is virified if id_column <QDirModel::columnCount()
    but no if id_column >=QDirModel::columnCount()

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

    Default Re: Creating a QAbstractItemModel for QTreeView

    Could you check if your columnCount() method is called at all?

  8. #8

    Default Re: Creating a QAbstractItemModel for QTreeView

    Did you ever find a solution to the column data not being added?

  9. #9
    Join Date
    Aug 2008
    Posts
    39
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Creating a QAbstractItemModel for QTreeView

    Your problem may have been similar to mine. What version of Qt are you using. I upgraded from 4.3.2 to 4.4.1 on solaris, and my problems went away.

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.