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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QStandardItemModel>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
for (int i = 0; i <= 41; i++)
{
ui
->tableView
->setIndexWidget
(model
->index
(i,
2,
QModelIndex()), btn
);
}
ui->tableView->setModel(model);
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QStandardItemModel>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QStandardItemModel *model = new QStandardItemModel(41,2,this);
for (int i = 0; i <= 41; i++)
{
QPushButton *btn = new QPushButton("E-Mail", this);
ui->tableView->setIndexWidget(model->index(i, 2, QModelIndex()), btn);
}
ui->tableView->setModel(model);
}
To copy to clipboard, switch view to plain text mode
Cap_ture.PNG
Bookmarks