QTableView表格中添加按钮

m_model = new QStandardItemModel;
ui->tableView->setModel(m_model);
auto item = m_model->index(m_index,11);        //定义第m_index行,第11列的单元格
QHBoxLayout *hlayout = new QHBoxLayout;
QWidget *wid = new QWidget;
int nowindex = m_index;
QPushButton *btn_view = new QPushButton("查看");
connect(btn_view,&QPushButton::clicked,[=](){viewPoint(nowindex);});
QPushButton *btn_mod = new QPushButton("修改");
connect(btn_mod,&QPushButton::clicked,[=](){modifyPoint(nowindex);});
QPushButton *btn_del = new QPushButton("删除");
connect(btn_del,&QPushButton::clicked,[=](){deletePoint(nowindex);});
hlayout->addWidget(btn_view,1,Qt::AlignCenter);
hlayout->addWidget(btn_mod,1,Qt::AlignCenter);
hlayout->addWidget(btn_del,1,Qt::AlignCenter);
hlayout->setMargin(0);
wid->setLayout(hlayout);
ui->tableView->setIndexWidget(item,wid);

你可能感兴趣的:(QT,qt,ui,开发语言)