如何在tablewidget添加按钮
1个回答
展开全部
1 定义一个按钮
[cpp] view plain copy
QPushButton * pBtn = new QPushButton();
2 链接信号与曹
[cpp] view plain copy
connect(pBtn, SIGNAL(clicked()), this, SLOT(OnBtnClicked()));
3 按钮添加到单元格内
[cpp] view plain copy
table->setCellWidget(0,0,pBtn); //如果点击按钮出现崩溃现象,就添加QTableWidgetItem 到按钮的那个单元格
4 实现按钮的事件
[cpp] view plain copy
void myPic::OnBtnClicked(void)
{
QPushButton * senderObj=qobject_cast<QPushButton *>(sender());
if(senderObj == 0)
{
return;
}
[cpp] view plain copy
QPushButton * pBtn = new QPushButton();
2 链接信号与曹
[cpp] view plain copy
connect(pBtn, SIGNAL(clicked()), this, SLOT(OnBtnClicked()));
3 按钮添加到单元格内
[cpp] view plain copy
table->setCellWidget(0,0,pBtn); //如果点击按钮出现崩溃现象,就添加QTableWidgetItem 到按钮的那个单元格
4 实现按钮的事件
[cpp] view plain copy
void myPic::OnBtnClicked(void)
{
QPushButton * senderObj=qobject_cast<QPushButton *>(sender());
if(senderObj == 0)
{
return;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询