QTableWidget添加按钮

来源:互联网 发布:2017凤凰网软件打不开 编辑:程序博客网 时间:2024/06/05 16:07
#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;
}
 
原创粉丝点击