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 hide/show all rows?(QTablewidget)

How to hide/show all rows?(QTablewidget)

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 4 Posters 11.7k 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.
  • E Engelard
    17 Nov 2018, 11:43

    @mrjj said in How to hide/show all rows?(QTablewidget):

    ui->tableWidget->clear(); also removes all rows.

    Knew that, but thanks anyway.

    @mrjj said in How to hide/show all rows?(QTablewidget):

    Can i ask why you need to hide such huge amount of rows?

    Hide all and then show only those which corresponds with value in it(showing like 20 of that rows is fast and easy, but hiding rest of 49980 individually is damn long time).

    M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 17 Nov 2018, 11:45 last edited by
    #5

    @Engelard
    Ok for such use case, you really want to do what @Slawomir_Piernikowski suggests and use
    QSortFilterProxyModel and show only the rows that matches some criteria.

    1 Reply Last reply
    6
    • S Slawomir_Piernikowski
      17 Nov 2018, 11:39

      If you want to see only some of the rows or none you can implement QSortFilterProxyModel and filter data.

      E Offline
      E Offline
      Engelard
      wrote on 17 Nov 2018, 12:12 last edited by Engelard
      #6

      @Slawomir_Piernikowski said in How to hide/show all rows?(QTablewidget):

      you can implement QSortFilterProxyModel

      I read manual in documentation, it assume that i should use function setModel(); to my tabWidget, but this function is private, and since my tabWidget is made in ui(Designer), i can't remake whole app, create new class just for inheritance, to much code should be repaired.

      Is there any other way to do something else, or at least access that private function?

      P.S. why this function even private... Such an obstacle for me now.

      M S 2 Replies Last reply 17 Nov 2018, 12:18
      0
      • E Engelard
        17 Nov 2018, 12:12

        @Slawomir_Piernikowski said in How to hide/show all rows?(QTablewidget):

        you can implement QSortFilterProxyModel

        I read manual in documentation, it assume that i should use function setModel(); to my tabWidget, but this function is private, and since my tabWidget is made in ui(Designer), i can't remake whole app, create new class just for inheritance, to much code should be repaired.

        Is there any other way to do something else, or at least access that private function?

        P.S. why this function even private... Such an obstacle for me now.

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 17 Nov 2018, 12:18 last edited by
        #7

        @Engelard
        Hi
        its private as QTablewidget uses a inner model.
        The Widgets version is just a wrapper for the View version.
        You could use
        QTableView with a QStandardItemModel instead.
        Code is also most the same, except you will add the Items to the model and not
        directly to Table.

        E 1 Reply Last reply 17 Nov 2018, 12:26
        1
        • M mrjj
          17 Nov 2018, 12:18

          @Engelard
          Hi
          its private as QTablewidget uses a inner model.
          The Widgets version is just a wrapper for the View version.
          You could use
          QTableView with a QStandardItemModel instead.
          Code is also most the same, except you will add the Items to the model and not
          directly to Table.

          E Offline
          E Offline
          Engelard
          wrote on 17 Nov 2018, 12:26 last edited by Engelard
          #8

          @mrjj Can you pls write some crucial lines which i should add? I really can't understand this concept of model and hardly understand the half of what you said))

          M 1 Reply Last reply 17 Nov 2018, 12:32
          0
          • E Engelard
            17 Nov 2018, 12:26

            @mrjj Can you pls write some crucial lines which i should add? I really can't understand this concept of model and hardly understand the half of what you said))

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 17 Nov 2018, 12:32 last edited by mrjj
            #9

            @Engelard
            There is sample here
            https://stackoverflow.com/questions/18964377/using-qtableview-with-a-model
            THey use a custom model
            class VehicleModel : public QAbstractTableModel

            You can just use
            http://doc.qt.io/qt-5/qstandarditemmodel.html
            It looks worse than it is.

            Basically you can do ( to add a row of data to the model)

            QList<QStandardItem *> items;
            
            items.append(new QStandardItem("Column 1 Text"));
            items.append(new QStandardItem("Column 2 Text"));
            
            QStandardItemModel* model = new QStandardItemModel(this);
            
            model->setColumnCount(2);
            model->appendRow(items);
            

            and set model to TableView.
            This is the same as when you addItem to the TableWidget.

            They then use setFilterFixedString ( on the QSortFilterProxyModel ) to filter the model.

            E 1 Reply Last reply 17 Nov 2018, 17:27
            6
            • E Engelard
              17 Nov 2018, 12:12

              @Slawomir_Piernikowski said in How to hide/show all rows?(QTablewidget):

              you can implement QSortFilterProxyModel

              I read manual in documentation, it assume that i should use function setModel(); to my tabWidget, but this function is private, and since my tabWidget is made in ui(Designer), i can't remake whole app, create new class just for inheritance, to much code should be repaired.

              Is there any other way to do something else, or at least access that private function?

              P.S. why this function even private... Such an obstacle for me now.

              S Offline
              S Offline
              Slawomir_Piernikowski
              wrote on 17 Nov 2018, 12:43 last edited by Slawomir_Piernikowski
              #10

              @Engelard
              It is always like this. Some widgets has some limitaions like for example private member to which there is no access without inheritens. In your case if you have such a problem it would be better to try to know QTableView and how works Model-View-Controlle.
              There is plenty articles but the best is Qt help documentation.
              Go to qt help and write in the search line: Model. next choose "Model/View Tutorial"

              1 Reply Last reply
              0
              • M mrjj
                17 Nov 2018, 12:32

                @Engelard
                There is sample here
                https://stackoverflow.com/questions/18964377/using-qtableview-with-a-model
                THey use a custom model
                class VehicleModel : public QAbstractTableModel

                You can just use
                http://doc.qt.io/qt-5/qstandarditemmodel.html
                It looks worse than it is.

                Basically you can do ( to add a row of data to the model)

                QList<QStandardItem *> items;
                
                items.append(new QStandardItem("Column 1 Text"));
                items.append(new QStandardItem("Column 2 Text"));
                
                QStandardItemModel* model = new QStandardItemModel(this);
                
                model->setColumnCount(2);
                model->appendRow(items);
                

                and set model to TableView.
                This is the same as when you addItem to the TableWidget.

                They then use setFilterFixedString ( on the QSortFilterProxyModel ) to filter the model.

                E Offline
                E Offline
                Engelard
                wrote on 17 Nov 2018, 17:27 last edited by Engelard
                #11

                @mrjj said in How to hide/show all rows?(QTablewidget):

                and set model to TableView.

                told u i can't set it because it's private)

                Correct answer from Slawomir_Piernikowski , but will do so next time. Good lesson that was, every time when will create some huge/important widget - will do that only through manual creation of additional class with inheritance. No fast creation by hands with Designer anymore.

                M S 2 Replies Last reply 17 Nov 2018, 17:46
                0
                • E Engelard
                  17 Nov 2018, 17:27

                  @mrjj said in How to hide/show all rows?(QTablewidget):

                  and set model to TableView.

                  told u i can't set it because it's private)

                  Correct answer from Slawomir_Piernikowski , but will do so next time. Good lesson that was, every time when will create some huge/important widget - will do that only through manual creation of additional class with inheritance. No fast creation by hands with Designer anymore.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 17 Nov 2018, 17:46 last edited by
                  #12

                  @Engelard
                  "set model to TableView" -> TableVIEW allows setModel :)
                  You are using the Widget version. which dont allow it.

                  • No fast creation by hands with Designer anymore.

                  It has nothing to do with Designer. :)
                  TableWidget is simply slow with that many items and your method of hiding rows
                  You can insert a TableView in designer too.

                  So its not about using Designer or not.
                  You can even use designer with custom classes too.
                  So even if you decide you need a custom class. There is nothing stopping you for using
                  Designer for some of the forms and then insert classes from code also.

                  So it was more that the class used could not fulfill the requirements of 100K rows and show hide them. :)
                  And yes, that came around as it was fast and easy to use TableWidget. and its meant to
                  be easy to use. However, ease of use comes with a price in this case.

                  E 2 Replies Last reply 18 Nov 2018, 11:11
                  4
                  • E Engelard
                    17 Nov 2018, 17:27

                    @mrjj said in How to hide/show all rows?(QTablewidget):

                    and set model to TableView.

                    told u i can't set it because it's private)

                    Correct answer from Slawomir_Piernikowski , but will do so next time. Good lesson that was, every time when will create some huge/important widget - will do that only through manual creation of additional class with inheritance. No fast creation by hands with Designer anymore.

                    S Offline
                    S Offline
                    Slawomir_Piernikowski
                    wrote on 17 Nov 2018, 19:12 last edited by Slawomir_Piernikowski
                    #13

                    @Engelard
                    Do not be disappointed. All widgets are only classes and you use them to create objects.
                    So it is only about object orientated programming. You have to get to know methods in classes and how to use them. But it takes some time.......but after you once write your soft it will be easier to use Model view control in your other project and then it will not take so much time.

                    1 Reply Last reply
                    0
                    • M mrjj
                      17 Nov 2018, 17:46

                      @Engelard
                      "set model to TableView" -> TableVIEW allows setModel :)
                      You are using the Widget version. which dont allow it.

                      • No fast creation by hands with Designer anymore.

                      It has nothing to do with Designer. :)
                      TableWidget is simply slow with that many items and your method of hiding rows
                      You can insert a TableView in designer too.

                      So its not about using Designer or not.
                      You can even use designer with custom classes too.
                      So even if you decide you need a custom class. There is nothing stopping you for using
                      Designer for some of the forms and then insert classes from code also.

                      So it was more that the class used could not fulfill the requirements of 100K rows and show hide them. :)
                      And yes, that came around as it was fast and easy to use TableWidget. and its meant to
                      be easy to use. However, ease of use comes with a price in this case.

                      E Offline
                      E Offline
                      Engelard
                      wrote on 18 Nov 2018, 11:11 last edited by Engelard
                      #14

                      @mrjj said in How to hide/show all rows?(QTablewidget):

                      "set model to TableView" -> TableVIEW allows setModel :)

                      To much tables on this week, did'nt see exactly what you wrote) I Will try it.

                      UPDATE.

                      Read about tableView. There is so much to remake, replaced my tabWid with View, about 200 errors got, will take a day to remake whole app)) Or maybe more.

                      QTableView (and other Model/View widgets) is preferable for displaying a significant amount of data.

                      Well, did'nt know that when i started my app)

                      M 1 Reply Last reply 18 Nov 2018, 13:19
                      0
                      • E Engelard
                        18 Nov 2018, 11:11

                        @mrjj said in How to hide/show all rows?(QTablewidget):

                        "set model to TableView" -> TableVIEW allows setModel :)

                        To much tables on this week, did'nt see exactly what you wrote) I Will try it.

                        UPDATE.

                        Read about tableView. There is so much to remake, replaced my tabWid with View, about 200 errors got, will take a day to remake whole app)) Or maybe more.

                        QTableView (and other Model/View widgets) is preferable for displaying a significant amount of data.

                        Well, did'nt know that when i started my app)

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 18 Nov 2018, 13:19 last edited by
                        #15

                        @Engelard
                        well that 200 errors is mostly about same stuff i assume.
                        But yeah, switching to View can be a bit involving later.

                        Btw, you can try
                        ui->tableWidget->setUpdatesEnabled(false);
                        for loop with hiderow
                        ui->tableWidget->setUpdatesEnabled(true);
                        and see if that speed it up.
                        But changing to View version will make you more happy in the long run :)

                        1 Reply Last reply
                        0
                        • C Online
                          C Online
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on 18 Nov 2018, 14:51 last edited by
                          #16

                          @mrjj said in How to hide/show all rows?(QTablewidget):

                          Btw, you can try
                          ui->tableWidget->setUpdatesEnabled(false);
                          for loop with hiderow
                          ui->tableWidget->setUpdatesEnabled(true);
                          and see if that speed it up.

                          Will not help here - QHeaderView::setSectionHidden() doesn't care for such things and this is simply not meant to hide more than a few rows.

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          M 1 Reply Last reply 18 Nov 2018, 15:00
                          2
                          • M mrjj
                            17 Nov 2018, 17:46

                            @Engelard
                            "set model to TableView" -> TableVIEW allows setModel :)
                            You are using the Widget version. which dont allow it.

                            • No fast creation by hands with Designer anymore.

                            It has nothing to do with Designer. :)
                            TableWidget is simply slow with that many items and your method of hiding rows
                            You can insert a TableView in designer too.

                            So its not about using Designer or not.
                            You can even use designer with custom classes too.
                            So even if you decide you need a custom class. There is nothing stopping you for using
                            Designer for some of the forms and then insert classes from code also.

                            So it was more that the class used could not fulfill the requirements of 100K rows and show hide them. :)
                            And yes, that came around as it was fast and easy to use TableWidget. and its meant to
                            be easy to use. However, ease of use comes with a price in this case.

                            E Offline
                            E Offline
                            Engelard
                            wrote on 18 Nov 2018, 14:53 last edited by
                            #17

                            @mrjj said in How to hide/show all rows?(QTablewidget):

                            TableWidget is simply slow with that many items and your method of hiding rows

                            Why then TableWidget exist? Why they dont just left only View type, what can do tableWidget what can't View?

                            @mrjj said in How to hide/show all rows?(QTablewidget):

                            You can even use designer with custom classes too.

                            How. In my test program i created tableView in designer, how should i create new class for it? I rly can't get it, how it might be created from ui and my custom class simultaneously.

                            M 1 Reply Last reply 18 Nov 2018, 14:58
                            0
                            • E Engelard
                              18 Nov 2018, 14:53

                              @mrjj said in How to hide/show all rows?(QTablewidget):

                              TableWidget is simply slow with that many items and your method of hiding rows

                              Why then TableWidget exist? Why they dont just left only View type, what can do tableWidget what can't View?

                              @mrjj said in How to hide/show all rows?(QTablewidget):

                              You can even use designer with custom classes too.

                              How. In my test program i created tableView in designer, how should i create new class for it? I rly can't get it, how it might be created from ui and my custom class simultaneously.

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 18 Nov 2018, 14:58 last edited by mrjj
                              #18

                              @Engelard
                              Hi
                              It exists for use cases with just a few hundred items and
                              is meant as a convenient class. ( it is a View with private model)

                              • how it might be created from ui and my custom class simultaneously.
                                You can use a feature of Creator called promotion.
                                http://doc.qt.io/qt-5/designer-using-custom-widgets.html
                                Think of it as runtime replace. You place say a normal Widget on the form.
                                and then promote it to your widget subclass. Then when run, its your class
                                instead of the default one.
                              E 1 Reply Last reply 18 Nov 2018, 16:57
                              1
                              • C Christian Ehrlicher
                                18 Nov 2018, 14:51

                                @mrjj said in How to hide/show all rows?(QTablewidget):

                                Btw, you can try
                                ui->tableWidget->setUpdatesEnabled(false);
                                for loop with hiderow
                                ui->tableWidget->setUpdatesEnabled(true);
                                and see if that speed it up.

                                Will not help here - QHeaderView::setSectionHidden() doesn't care for such things and this is simply not meant to hide more than a few rows.

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 18 Nov 2018, 15:00 last edited by
                                #19

                                @Christian-Ehrlicher
                                Ah, i though HideRow was something else :)
                                So treeWidget->setUniformRowHeights(true);
                                will not speed anything up either i assume.

                                1 Reply Last reply
                                0
                                • M mrjj
                                  18 Nov 2018, 14:58

                                  @Engelard
                                  Hi
                                  It exists for use cases with just a few hundred items and
                                  is meant as a convenient class. ( it is a View with private model)

                                  • how it might be created from ui and my custom class simultaneously.
                                    You can use a feature of Creator called promotion.
                                    http://doc.qt.io/qt-5/designer-using-custom-widgets.html
                                    Think of it as runtime replace. You place say a normal Widget on the form.
                                    and then promote it to your widget subclass. Then when run, its your class
                                    instead of the default one.
                                  E Offline
                                  E Offline
                                  Engelard
                                  wrote on 18 Nov 2018, 16:57 last edited by Engelard
                                  #20

                                  @mrjj said in How to hide/show all rows?(QTablewidget):

                                  You can use a feature of Creator called promotion.

                                  Hey nice feature. The only thing i don't like, is this message EVERY time i compile my project(brow.h is my mainWindow, main class if you wish):

                                  0_1542560263077_cmonnn.jpg

                                  And every time clicking yes yes yes...

                                  1 Reply Last reply
                                  0
                                  • C Online
                                    C Online
                                    Christian Ehrlicher
                                    Lifetime Qt Champion
                                    wrote on 18 Nov 2018, 17:12 last edited by
                                    #21

                                    Then close the ui_brow.h - since it is generated it will be created on every compile.

                                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                    Visit the Qt Academy at https://academy.qt.io/catalog

                                    1 Reply Last reply
                                    4

                                    14/21

                                    18 Nov 2018, 11:11

                                    • Login

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