[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
}
QVector<QComboBox*> cbDianYafor(int i=0i<20i++)
{
QComboBox *tmp= new QComboBox()
tmp->addItem("")
tmp->addItem("100")
tmp->addItem("150")
tmp->addItem("300")
cbDianYa.append(tmp)
}
for(int j=0j<20j++)
{
ui->tableWidget->setCellWidget(j,0,cbDianYa.at(j))
}
这回可行,我试过了,用个向量解决问题
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)