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. [SOLVED] QTableView how to limit shown rows
QtWS25 Last Chance

[SOLVED] QTableView how to limit shown rows

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 14.9k 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
    Vaquita Tim
    wrote on last edited by
    #4

    It shouldn't be too hard to make a sub-class of QTableView. There's a handy isRowHidden function you can use to limit which rows to call the model data function. You just need to figure out where this happens in the current QTableView...

    The Qt Documentation seems to be quite helpful ;-) But I've never done it myself

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tecnova
      wrote on last edited by
      #5

      just had the same idea. hide the rows that are not in the range and show more when I scroll down or up.
      But does QTableView resize only the shown rows?
      When it would resize the hidden rows also, that wouldn't help me :(.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tom C
        wrote on last edited by
        #6

        You can try to insert a proxy model between your view and your model. With the proxy model you can filter the model in order to get the 50-100 rows that have to be shown by the view.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vaquita Tim
          wrote on last edited by
          #7

          bq. insert a proxy model
          Hmmm - or, just have the model check the view to see if the asked for values are visible or not. It doesn't sound very nice to me...

          bq. QTableView resize only the shown rows?
          I'm not sure if you or I have got the wrong end of the stick here. Anyway, my point is that the QTableView class itself knows which rows/columns are visible (depending on how you resize the width/height of the rows/columns and the overall widget size) and thus only asks the model for the data it needs.

          Actually I'm a little suprised (but not very) that QTableModel itself doesn't do this already. And a little nervous for you that the QTableModel is quite complicated.

          So, probably Tom's idea is the most pragmatic (even if it's not "right").

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tecnova
            wrote on last edited by
            #8

            well I have to build a new filter for my table anyway. I will try it with the Proxy Model

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tom C
              wrote on last edited by
              #9

              I think the view can be configure to resize itself automatically.

              See :
              "QHeaderView::setResizeMode":http://qt-project.org/doc/qt-5.0/qtwidgets/qheaderview-compat.html#setResizeMode
              "QTableView::horizontalHeader":http://qt-project.org/doc/qt-5.0/qtwidgets/qtableview.html#horizontalHeader

              By doing so, you do not have to resize the view programmatically.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Tecnova
                wrote on last edited by
                #10

                ok i solved it now with a proxy model
                Thanks for the help

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tktan
                  wrote on last edited by
                  #11

                  Tecnova,

                  Do you have a generic code of your solution that can be shared with me? I'm interested to do the same.

                  I'm using QTreeWidget to display a list of items that is queried from a server. I intend to limit it to display a maximum of 50 items. If returned list of items exceed 50, idea is to present a little navigator at the bottom of that window to allow user to click next 50-100, etc.

                  Seems very same to what you implement and was wondering whether you could share your solution or direct me to an example that you refer to in your implementation?

                  Thanks in advance.

                  Regards,

                  TTK

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    Tecnova
                    wrote on last edited by
                    #12

                    Sry I dont have acces to the source code anymore.
                    But I can tell you what I did.

                    First of all I stoped using the QT Widget and made my own View, like you read above. Than I used the Proxy Model for filtering. The Advantage of the Proxy Model is that it is between your View(the actual data that is shown on you application) and the whole database. In the proxy model you can define what data of the database will be shown and which not.

                    In my task I did create my own datastructure(database) from files I did read in. So I did know the row number. In my Filter I simply did a range of 500 rows. Than I did overwride the keyboard buttons up and down to load the next/previous 500 rows, simply by setting the minrow and maxrow +/- 500 in my Filter. I accessed the Filter by saving his reference(pointer) when i created him. and than i simly did View.refresh() or something like that to reset the view with the new filter.

                    I know Views can be a bit complicated at the beginning, but they will really help you when you have to do complex things with your data.

                    An other oppertunity what you can do is hide every other row.
                    @void hideshow(int direction)
                    {
                    //not shure with that static you can also put them in a class
                    static int minrow = 0;
                    static int maxrow = 50;

                    if(maxrow == widget.getMaxRow() || minrow == 0) // do nothing when //maxrow or minrow gets over the given data range
                    return;

                    for(int i = minrow; i < maxrow; i++;)
                    widget.hideRow(i);

                    switch(direction)
                     case 1: //down
                               minrow += 50;
                               maxrow += 50;
                               for(int j = minrow; j < maxrow; j++;)
                                   widget.showRow(j);
                               break; 
                     case 2: //up
                               minrow -= 50;
                               maxrow -= 50;
                               for(int j = minrow; j < maxrow; j++;)
                                   widget.showRow(j);
                               break;
                    

                    return;
                    }@

                    when you want to use this code you have to hide every top level row when initialising your widget except the top 50 one. You can also override some keyboard buttons and redefine they´re meaning.

                    Thats all what I can help you so far. For the views you should better look up other forums or the Qt tutorials.
                    I hope it helps you :/

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      tktan
                      wrote on last edited by
                      #13

                      Thanks for the quick response! I'll take your advice on reading up the proxy model on filtering the data. I think the address book example in QT is quite relevant. Going through that now.

                      Thanks!

                      Regards,

                      TTK

                      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