QTableWidget获取其中子cell发出信号的对象!

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

以上按钮不能放在QWidget再放到Cell里

猜你喜欢

转载自blog.csdn.net/qq_36533978/article/details/85127618
今日推荐