I used backword loop, removing items from last,
As shown below
Qt Code:
int m=ui->tableWidget_ouput->rowCount(); while(m>=NewRow) { ui->tableWidget_ouput->removeRow(m); m--; }To copy to clipboard, switch view to plain text mode
I used backword loop, removing items from last,
As shown below
Qt Code:
int m=ui->tableWidget_ouput->rowCount(); while(m>=NewRow) { ui->tableWidget_ouput->removeRow(m); m--; }To copy to clipboard, switch view to plain text mode
Ehm, what about QTableWidget::clearContents() or QTableWidget::clear()?
EDIT: Forget it, read too fast, didn't see NewRow...
I went there too. Those functions remove the content from the table but leave the dimensions the same, i.e. rowCount() is unchanged. Contrast that with removeRow(), as used in the original post, which actually shrinks the table. I guess it really depends on what your application actually requires.
Wouldn't this be the quickest?
Qt Code:
ui->tableWidget->setRowCount(NewRow);To copy to clipboard, switch view to plain text mode
I don't know what happens with those excessive items, if they are deleted or not.
Because I was curious:Yes, they are!Qt Code:
void QTableModel::setRowCount(int rows) { int rc = verticalHeaderItems.count(); if (rows < 0 || rc == rows) return; if (rc < rows) insertRows(qMax(rc, 0), rows - rc); else removeRows(qMax(rows, 0), rc - rows); }To copy to clipboard, switch view to plain text mode
Bookmarks