Results 1 to 3 of 3

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

Threaded View

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

    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

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.