I have created a QTableWidget
in which I've used setCellWidget(QWidget*)
. I've set QLineEdit
in the cell widget. I've also created a delete button and clicking that button sends a signal to the function deleteRow
. I've also used a function currentRow()
to get the current row, but it returns -1
because of the QLineEdit
. The code snippet is below.
void createTable() {
m_table = new QTableWidget(QDialog); //member variable
for (int i = 0; i < 3; i++)
{
QLineEdit *lineEdit = new QLineEdit(m_table);
m_table->setCellWidget(i, 0, lineEdit);
}
QPushButton *deleteBut = new QPushButton(QDiaolg);
connect(deleteBut, SIGNAL(clicked()), QDialog, SLOT(editRow()));
}
editRow() {
int row = m_table->currentRow(); // This gives -1
m_table->remove(row);
}
In above scenario I click in the QLineEdit
and then click on the button delete. Please help me out with a solution.