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.
  • mrjjM mrjj

    @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.

    EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on 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.

    mrjjM S 2 Replies Last reply
    0
    • EngelardE Engelard

      @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.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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.

      EngelardE 2 Replies Last reply
      4
      • EngelardE Engelard

        @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 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
        • mrjjM mrjj

          @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.

          EngelardE Offline
          EngelardE Offline
          Engelard
          wrote on 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)

          mrjjM 1 Reply Last reply
          0
          • EngelardE Engelard

            @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)

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on 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
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 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

              mrjjM 1 Reply Last reply
              2
              • mrjjM mrjj

                @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.

                EngelardE Offline
                EngelardE Offline
                Engelard
                wrote on 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.

                mrjjM 1 Reply Last reply
                0
                • EngelardE Engelard

                  @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.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 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.
                  EngelardE 1 Reply Last reply
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    @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.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 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
                    • mrjjM mrjj

                      @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.
                      EngelardE Offline
                      EngelardE Offline
                      Engelard
                      wrote on 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
                      • Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 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

                        • Login

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