在QTableWidget中可以添加多种Qt的空间信息,本文只以QPushButton为例进行说明:

// 创建QPushButton控件
QPushButton *pBtn = new QPushButton();  

// 绑定信号
connect(pBtn, SIGNAL(clicked()), this, SLOT(OnBtnClicked()));  

// 在QTableWidget中添加控件
tableWidget->setCellWidget(0,0,pBtn); 

// 绑定的响应函数
void OnBtnClicked(void)  
{  
    QPushButton *senderObj=qobject_cast<QPushButton*>(sender());  
    if(senderObj == nullptr)  
    {  
        return;  
    }  
    QModelIndex idx =tableWidget->indexAt(QPoint(senderObj->frameGeometry().x(),senderObj->frameGeometry().y()));  
    int row=idx.row();  
    // 其他响应信息......
}  

当然,也可以添加其他控件、布局、贴图等。

 

posted on 2017-03-15 18:42  xuhui24  阅读(14791)  评论(1编辑  收藏  举报