#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QDebug>
#include <QModelIndex>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPushButton * btn = new QPushButton(ui->tableWidget);
ui->tableWidget->setRowCount(3);
ui->tableWidget->setCellWidget(1,0,btn);
QPushButton * btn01 = new QPushButton(ui->tableWidget);
ui->tableWidget->setCellWidget(1,1,btn01);
btn->setText(tr("check"));
connect(btn,&QPushButton::clicked,this,[=](){
qDebug()<<"this is ok";
QPushButton *obj= (QPushButton*)sender();
int x = obj->frameGeometry().x();
int y = obj->frameGeometry().y();
QModelIndex index = ui->tableWidget->indexAt(QPoint(x, y));
int row = index.row();
int column = index.column();
qDebug()<<"row="<<row<<"column="<<column;
});
}
MainWindow::~MainWindow()
{
delete ui;
}
QT tablewidget插入button(记录一下)
最新推荐文章于 2024-08-11 12:37:03 发布