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 to delete whole table in qtablewidget?

How to delete whole table in qtablewidget?

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidget
8 Posts 6 Posters 17.8k 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.
  • V Offline
    V Offline
    vasu_gupta
    wrote on last edited by A Former User
    #1

    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?

    joeQJ 1 Reply Last reply
    0
    • V vasu_gupta

      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?

      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by joeQ
      #2

      @vasu_gupta Hi, friend. Welcome.

      About the content of table, you can use QTableWidget::clear to clear. But the table header, you should reset or delete them. you can use takeHorizontalHeaderItem(int column) to take header item, and then to delete it.

      Just do it!

      1 Reply Last reply
      1
      • Vinod KuntojiV Offline
        Vinod KuntojiV Offline
        Vinod Kuntoji
        wrote on last edited by
        #3

        @vasu_gupta ,

        You can use hide,setvisible(false) for header. To remove all the contents, use setrowcount(0).

        C++, Qt, Qt Quick Developer,
        PthinkS, Bangalore

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4
          QAbstractItemModel* const mdl = tablewidget->model();
          mdl->removeRows(0,mdl->rowCount());
          mdl->removeColumns(0,mdl->columnCount());
          

          "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

          Taz742T J 2 Replies Last reply
          5
          • VRoninV VRonin
            QAbstractItemModel* const mdl = tablewidget->model();
            mdl->removeRows(0,mdl->rowCount());
            mdl->removeColumns(0,mdl->columnCount());
            
            Taz742T Offline
            Taz742T Offline
            Taz742
            wrote on last edited by Taz742
            #5

            @Vinod-Kuntoji said in how to delete whole table in qtablewidget??:

            To remove all the contents, use setrowcount(0).

            Will the model be cleared?

            VRoninV 1 Reply Last reply
            0
            • Taz742T 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?

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #6
              • What removeRows does
              • What removeColumns does (if called after remove rows it basically only clears horizontal headers)

              "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

              Taz742T 1 Reply Last reply
              3
              • VRoninV VRonin
                • What removeRows does
                • What removeColumns does (if called after remove rows it basically only clears horizontal headers)
                Taz742T Offline
                Taz742T Offline
                Taz742
                wrote on last edited by Taz742
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • VRoninV VRonin
                  QAbstractItemModel* const mdl = tablewidget->model();
                  mdl->removeRows(0,mdl->rowCount());
                  mdl->removeColumns(0,mdl->columnCount());
                  
                  J Offline
                  J Offline
                  Josecarlnivore
                  wrote on last edited by
                  #8

                  @VRonin I love this. It helped a lot. Thanks.

                  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