Clearing a QTtableview
-
Hi All,
I'm fairly new to QT but am having an issue with clearing QT table view. Basically I have two tables views, one filled with items that I can drag and drop to the second one. What I'd like to do is click on a clear button to erase the items from the second view.
I've tried clear but that class function doesn't exist, I tried
[code]
QItemSelectionModel *mod2 = ui->tableView_2->selectionModel();while( mod2->model( )->rowCount( ) ) { mod2->model()->removeRow( 0, &mod2 ); }
[/code]
I thought I could use removeRow, however I don't know what the second parameter should be or even if I did would it clear the box?
Can anyone advise on this please? I think I'm talking myself in circles. Thanks. -
You can easily do that by removing all rows from the model itself
model()->removeRows(0, model()->rowCount());
in your case it should be :
ui->tableView_2->model()->removeRows(0,ui->tableView_2->model()->rowCount());
-
Thanks. Worked a treat. Easy for some, tricky for me :)
-
You are welcome, There is another function as clear() - Removes all items (including header items) from the model and sets the number of rows and columns to zero.