qtablewidget最后一列加上一个删除按钮
如题,点击删除按钮则删除这一行,行数不固定,请问怎么做?
[解决办法]
自定义button 添加一个属性 ID 这个ID对应的是TableWidget的列号。我记得button里面有自带的这个属性,我忘记是哪一个了,楼主可以在点击button时查看ID对应的调用TableWidget删除行,然后销毁或者hide掉对应的按钮
[解决办法]
1.添加按钮
QPushButton * pBtn = new QPushButton ();
connect(pBtn, SIGNAL(clicked()), this, SLOT(OnBtnTableDeleteClicked()));
m_pTableFood->setCellWidget(row,3,pBtn);
void OnBtnTableDeleteClicked(void)
{
QPushButton * senderObj=qobject_cast<QPushButton *>(sender());
if(senderObj == 0)
return;
QModelIndex index = m_pTableFood->indexAt(QPoint(senderObj->frameGeometry().x(),senderObj->frameGeometry().y()));
int row = index.row();
m_pTableFood->removeRow(row);
}