I created a table view like this:
I have a create button to create new rows and as you can see I defined a button for each row to delete that row by this code:
int i = 0;
QPushButton *viewButton;
QStandardItemModel *model;
void MainWindow::on_pushButton_clicked()
{
model->appendRow(new QStandardItem(QString("")));
viewButton = new QPushButton();
viewButton->setText("Delete " + QString::number(i));
ui->tableView->setIndexWidget(model->index(i , 7), viewButton);
connect(viewButton , SIGNAL(clicked()) , this , SLOT(button_clicked()));
i++;
}
and I created a slot for each button clicked for remove a row:
void MainWindow::button_clicked()
{
// by this line I can get the sender of signal
QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
}
as you can see I know witch button sends signal and now I need to delete that row. here is my question: how can I get the row of sender button in table view to remove that row? I searched everywhere and I didn’t realise how to get the row and column of an item.