Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How not to delete column names in QTableWidget
Forum Updated to NodeBB v4.3 + New Features

How not to delete column names in QTableWidget

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mark_ua_1999
    wrote on last edited by
    #1

    I am trying to delete all rows from tablewidget but it delete column names also
    my code
    while (ui->tableWidget->rowCount() > 1)
    {
    ui->tableWidget->removeRow(0);
    }
    0_1511172688348_Capture.PNG
    0_1511172698333_Capture1.PNG
    Do you have any ideas how to resolve it thanks.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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)

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      M 1 Reply Last reply
      0
      • VRoninV VRonin

        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)

        M Offline
        M Offline
        mark_ua_1999
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          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?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          M 1 Reply Last reply
          2
          • VRoninV VRonin

            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?

            M Offline
            M Offline
            mark_ua_1999
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved