I want to filling the second column of my TableView with pushbuttons so I wrote the code below but the output is not what I want. Please see the attached snapshot of the output. As can been seen in the output window, the buttons are stacked at the top left-hand corner instead of being listed on the second column
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QPushButton>
  4. #include <QStandardItemModel>
  5.  
  6. MainWindow::MainWindow(QWidget *parent) :
  7. QMainWindow(parent),
  8. ui(new Ui::MainWindow)
  9. {
  10. ui->setupUi(this);
  11.  
  12. QStandardItemModel *model = new QStandardItemModel(41,2,this);
  13.  
  14.  
  15. for (int i = 0; i <= 41; i++)
  16. {
  17. QPushButton *btn = new QPushButton("E-Mail", this);
  18. ui->tableView->setIndexWidget(model->index(i, 2, QModelIndex()), btn);
  19. }
  20. ui->tableView->setModel(model);
  21. }
To copy to clipboard, switch view to plain text mode 
Cap_ture.PNG