Results 1 to 2 of 2

Thread: Qtableview insert row and column

  1. #1
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: Qtableview insert row and column

    hello every one i am working in Qt .i need help i have drag and drop a tableview in my main window

    now i want to display item in it but i have no idea how to do it how to set model how to append row and column i check documentation but i don't know about the sequence i am totally stuck i any one can help i will be very thank full.
    Last edited by maarvi; 28th June 2011 at 19:10.

  2. #2
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qtableview insert row and column

    hi

    here a small table view example that i used with QStandardItemModel :

    Qt Code:
    1. #include <QStandardItemModel>
    2. #include <QHeaderView>
    3.  
    4.  
    5. private:
    6.  
    7.  
    8. QModelIndex modelIndex;
    9.  
    10. QStandardItem *item00;
    11. QStandardItem *item01;
    12. QStandardItem *item02;
    13. QStandardItem *item03;
    14. QStandardItem *item10;
    15. QStandardItem *item11;
    16. QStandardItem *item12;
    17. QStandardItem *item13;
    18.  
    19. QStringList horizontalHeader;
    20. QStringList verticalHeader;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::fillTable()
    2. {
    3.  
    4. horizontalHeader.append("SPH");
    5. horizontalHeader.append("CYL");
    6. horizontalHeader.append("AXIS");
    7. horizontalHeader.append("A.D.D");
    8.  
    9. verticalHeader.append("R");
    10. verticalHeader.append("L");
    11.  
    12.  
    13.  
    14. model.index(1,1,model.index(0,0));
    15. model.setHorizontalHeaderLabels(horizontalHeader);
    16. model.setVerticalHeaderLabels(verticalHeader);
    17.  
    18.  
    19. item00 = new QStandardItem(QString("0"));
    20. model.setItem(0, 0, item00);
    21.  
    22. item01 = new QStandardItem(QString("0"));
    23. model.setItem(0, 1, item01);
    24.  
    25. item02 = new QStandardItem(QString("0"));
    26. model.setItem(0, 2, item02);
    27.  
    28. item03 = new QStandardItem(QString("0"));
    29. model.setItem(0, 3, item03);
    30.  
    31. item10 = new QStandardItem(QString("0"));
    32. model.setItem(1, 0, item10);
    33.  
    34. item11 = new QStandardItem(QString("0"));
    35. model.setItem(1, 1, item11);
    36.  
    37. item12 = new QStandardItem(QString("0"));
    38. model.setItem(1, 2, item12);
    39.  
    40. item13 = new QStandardItem(QString("0"));
    41. model.setItem(1, 3, item13);
    42.  
    43. ui->tableView->setModel(&model);
    44.  
    45. ui->tableView->resizeRowsToContents();
    46. ui->tableView->resizeColumnsToContents();
    47. }
    To copy to clipboard, switch view to plain text mode 

    use the loop to skip the repeated statments.

    good luck !

Similar Threads

  1. Replies: 1
    Last Post: 13th April 2011, 00:43
  2. how coult this happen with the QTableView Column insert?
    By xiongxiongchuan in forum Qt Programming
    Replies: 6
    Last Post: 13th December 2010, 07:32
  3. Insert into array column
    By wirasto in forum Newbie
    Replies: 3
    Last Post: 9th November 2009, 16:07
  4. Select row in QTableView after insert.
    By fede in forum Newbie
    Replies: 1
    Last Post: 14th April 2009, 16:18
  5. Insert QCheckBox into QTableView
    By wind in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2006, 17:15

Tags for this Thread

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.