QTableWidget中添加QPushButton


在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();  
    // 其他响应信息......
}  

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM