QTableWidget添加按钮

#include "table.h"
Table::Table(QWidget *parent) :
    QFrame(parent)
{
    setupUi(this);
//    init();
}
Table::~Table()
{
}
void Table::init()
{
    tableWidget->setColumnCount(3);
    QStringList starr;
    starr.append("ss");
    starr.append("aa");
    starr.append("dd");
    tableWidget->setHorizontalHeaderLabels(starr);
    int nrow = tableWidget->rowCount();
    tableWidget->insertRow(nrow);
    btn = new QPushButton;
    btn1 = new QPushButton;
    btn2 = new QPushButton;
    btn->setText(tr("123"));
    btn1->setText(tr("1234"));
    btn2->setText(tr("12345"));
    tableWidget->setCellWidget(nrow, 0, btn);
    tableWidget->setCellWidget(nrow, 1, btn1);
    tableWidget->setCellWidget(nrow, 2, btn2);
    connect(btn, SIGNAL(clicked(bool)), this, SLOT(push()));
    connect(btn1, SIGNAL(clicked(bool)), this, SLOT(push1()));
    connect(btn2, SIGNAL(clicked(bool)), this, SLOT(push2()));
}
void Table::push()
{
    int x = btn->frameGeometry().x();
    int y = btn->frameGeometry().y();
    QModelIndex index = tableWidget->indexAt(QPoint(x,y));
    int row = index.row();
    int column = index.column();
    qDebug()<<row<<column;
}
void Table::push1()
{
    int x = btn1->frameGeometry().x();
    int y = btn1->frameGeometry().y();
    QModelIndex index = tableWidget->indexAt(QPoint(x,y));
    int row = index.row();
    int column = index.column();
    qDebug()<<row<<column;
}
void Table::push2()
{
    int x = btn2->frameGeometry().x();
    int y = btn2->frameGeometry().y();
    QModelIndex index = tableWidget->indexAt(QPoint(x,y));
    int row = index.row();
    int column = index.column();
    qDebug()<<row<<column;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值