Results 1 to 3 of 3

Thread: Inserting QStandardItems to the child rows and columns in QStandardItemModel

  1. #1
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Inserting QStandardItems to the child rows and columns in QStandardItemModel

    Hi all!
    There is code which helps to build the tree (picturied lower)

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char** argv)
    4. {
    5. QApplication app(argc, argv);
    6. QStandardItemModel model(5, 3);
    7.  
    8. for (int nTopRow = 0; nTopRow < 5; ++nTopRow) {
    9. QModelIndex index = model.index(nTopRow, 0);
    10. model.setData(index, "item" + QString::number(nTopRow + 1));
    11.  
    12. model.insertRows(0, 4, index);
    13. model.insertColumns(0, 3, index);
    14. for (int nRow = 0; nRow < 4; ++nRow) {
    15. for (int nCol = 0; nCol < 3; ++nCol) {
    16. QString strPos = QString("%1,%2").arg(nRow).arg(nCol);
    17. model.setData(model.index(nRow, nCol, index), strPos);
    18. }
    19. }
    20. }
    21.  
    22. QTreeView treeView;
    23. treeView.setModel(&model);
    24. treeView.show();
    25.  
    26. return app.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    My task is to insert QStandardItems in the child rows and columns.
    tried
    void QStandardItemModel::setItem ( int row, int column, QStandardItem * item )
    but but the model did not change the count of its rows and columns after new rows and colums have been inserted

    do you have any ideas?
    Thank you
    Attached Images Attached Images
    Last edited by ru_core; 23rd July 2008 at 17:52. Reason: updated contents

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inserting QStandardItems to the child rows and columns in QStandardItemModel

    Where is your code calling setItem()?

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

    Default Re: Inserting QStandardItems to the child rows and columns in QStandardItemModel

    Quote Originally Posted by caduel View Post
    Where is your code calling setItem()?
    I just tried to insert it, but have no ideas how to set the Items to the inserted rows

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.