How to delete whole table in qtablewidget?
-
wrote on 22 Nov 2017, 06:04 last edited by A Former User
I want to destroy the content of whole table including the horizontalheader, verticalheader,and all the items so I can create a fresh table, how can I do that I tried clear and remove ow but header were not removed by so, since I want to remove all table content is there any way to do so?
-
I want to destroy the content of whole table including the horizontalheader, verticalheader,and all the items so I can create a fresh table, how can I do that I tried clear and remove ow but header were not removed by so, since I want to remove all table content is there any way to do so?
wrote on 22 Nov 2017, 06:33 last edited by joeQ@vasu_gupta Hi, friend. Welcome.
About the content of table, you can use
QTableWidget::clear
to clear. But the table header, you shouldreset
ordelete
them. you can usetakeHorizontalHeaderItem(int column)
to take header item, and then to delete it. -
wrote on 22 Nov 2017, 06:35 last edited by
You can use hide,setvisible(false) for header. To remove all the contents, use setrowcount(0).
-
wrote on 22 Nov 2017, 08:11 last edited by
QAbstractItemModel* const mdl = tablewidget->model(); mdl->removeRows(0,mdl->rowCount()); mdl->removeColumns(0,mdl->columnCount());
-
QAbstractItemModel* const mdl = tablewidget->model(); mdl->removeRows(0,mdl->rowCount()); mdl->removeColumns(0,mdl->columnCount());
wrote on 22 Nov 2017, 09:47 last edited by Taz742@Vinod-Kuntoji said in how to delete whole table in qtablewidget??:
To remove all the contents, use setrowcount(0).
Will the model be cleared?
-
@Vinod-Kuntoji said in how to delete whole table in qtablewidget??:
To remove all the contents, use setrowcount(0).
Will the model be cleared?
wrote on 22 Nov 2017, 10:13 last edited by VRonin- What removeRows does
- What removeColumns does (if called after remove rows it basically only clears horizontal headers)
-
- What removeRows does
- What removeColumns does (if called after remove rows it basically only clears horizontal headers)
wrote on 22 Nov 2017, 10:19 last edited by Taz742This post is deleted! -
QAbstractItemModel* const mdl = tablewidget->model(); mdl->removeRows(0,mdl->rowCount()); mdl->removeColumns(0,mdl->columnCount());
wrote on 12 Apr 2020, 11:06 last edited by@VRonin I love this. It helped a lot. Thanks.