How not to delete column names in QTableWidget

  • I am trying to delete all rows from tablewidget but it delete column names also
    my code
    while (ui->tableWidget->rowCount() > 1)
    Do you have any ideas how to resolve it thanks.

  • that really 100% depends on the model implementation. try ui->tableWidget->model()->removeRows(0,ui->tableWidget->model()->rowCount());

    If it doesn't work then separate QTableWidget into a QTableView and a QStandardItemModel (QStandardItemModel keeps the column headers even if there are no rows)

  • @VRonin I am trying it but it doesnt save column names (maybe there are way how to rewrite column names programly) 0_1511174454021_Capture.PNG

  • I checked the source and removeRows does not delete horizontalHeaderItems so the problem seems to be elsewhere. Can you show us what are you doing in the rest of your code?

  • @VRonin Thanks it helps (the matter I failed is that I use ui->tableWidget->clear(); )

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.