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. Infinite rows in QTableWidget?

Infinite rows in QTableWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 6 Posters 1.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.
  • P Offline
    P Offline
    Publicnamer
    wrote on last edited by
    #1

    Is there a way to tell QTableWidget to support infinite rows?

    If not, how could I detect when the user scrolls to the last row, in order to automatically add more for the user?

    artwawA JonBJ 2 Replies Last reply
    0
    • P Publicnamer

      Is there a way to tell QTableWidget to support infinite rows?

      If not, how could I detect when the user scrolls to the last row, in order to automatically add more for the user?

      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      @Publicnamer since rowCount() returns an int there is your theoretical limit.

      For more information please re-read.

      Kind Regards,
      Artur

      P 1 Reply Last reply
      1
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #3

        there are scroll mode, overshooting policy and frame rate settings. From them, you maybe able to know the actual location of scrolling and can decide when more rows are added or replaced.

        Maybe create a few frames and restart from the beginning when the last frame reaches. Sure, you update the frames after they pass.

        P 1 Reply Last reply
        0
        • artwawA artwaw

          @Publicnamer since rowCount() returns an int there is your theoretical limit.

          P Offline
          P Offline
          Publicnamer
          wrote on last edited by
          #4

          @artwaw I don't think you read my question.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            Hi
            Normally a custom model is used instead
            https://doc.qt.io/qt-5/qtwidgets-itemviews-fetchmore-example.html

            key here is
            bool canFetchMore(const QModelIndex &parent) const override;
            void fetchMore(const QModelIndex &parent) override;

            Adding QTableWidget* on scrolling might not be a smooth experience.

            P 1 Reply Last reply
            3
            • mrjjM mrjj

              Hi
              Normally a custom model is used instead
              https://doc.qt.io/qt-5/qtwidgets-itemviews-fetchmore-example.html

              key here is
              bool canFetchMore(const QModelIndex &parent) const override;
              void fetchMore(const QModelIndex &parent) override;

              Adding QTableWidget* on scrolling might not be a smooth experience.

              P Offline
              P Offline
              Publicnamer
              wrote on last edited by
              #6

              @mrjj Is the QTableWidget efficient so that if there are millions of empty cells, there is not a million times additional use of RAM?

              mrjjM 1 Reply Last reply
              0
              • P Publicnamer

                @mrjj Is the QTableWidget efficient so that if there are millions of empty cells, there is not a million times additional use of RAM?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Publicnamer
                Hi
                Yes, cells that are not allocated returns a NULL ptr for item() so it wont waste ram as such but
                creating millions of items will take time.

                So for huge models, often a custom model is used where the internal data structure fits the demand for such a huge amount of rows/items.

                But what will work best depends on what you actually need to do.

                P artwawA 2 Replies Last reply
                1
                • mrjjM mrjj

                  @Publicnamer
                  Hi
                  Yes, cells that are not allocated returns a NULL ptr for item() so it wont waste ram as such but
                  creating millions of items will take time.

                  So for huge models, often a custom model is used where the internal data structure fits the demand for such a huge amount of rows/items.

                  But what will work best depends on what you actually need to do.

                  P Offline
                  P Offline
                  Publicnamer
                  wrote on last edited by
                  #8

                  @mrjj Regarding the methods canFetchMore and fetchMore, I subclassed QTableWidget and added these methods,
                  but I am finding they are never called. Also none of the cells that previously appeared now appear.
                  I'm wondering if this is a slightly advanced topic and a more practical solution would be better.

                  Is there a way to detect when the user has scrolled to the last row?

                  1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    there are scroll mode, overshooting policy and frame rate settings. From them, you maybe able to know the actual location of scrolling and can decide when more rows are added or replaced.

                    Maybe create a few frames and restart from the beginning when the last frame reaches. Sure, you update the frames after they pass.

                    P Offline
                    P Offline
                    Publicnamer
                    wrote on last edited by
                    #9

                    @JoeCFD Looking in the class documentation and parent classes' as well, I don't see an overshoot policy mentioned anywhere.

                    JoeCFDJ 1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      You can check the visualRect of the last index. If it's valid then it means the index is shown.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      P 1 Reply Last reply
                      1
                      • P Publicnamer

                        @JoeCFD Looking in the class documentation and parent classes' as well, I don't see an overshoot policy mentioned anywhere.

                        JoeCFDJ Offline
                        JoeCFDJ Offline
                        JoeCFD
                        wrote on last edited by JoeCFD
                        #11

                        @Publicnamer

                            QScrollerProperties properties = QScroller::scroller( your widget )->scrollerProperties();
                            QVariant overshoot_policy = QVariant::fromValue< QScrollerProperties::OvershootPolicy >( QScrollerProperties::OvershootAlwaysOff );
                            properties.setScrollMetric( QScrollerProperties::VerticalOvershootPolicy, overshoot_policy );
                            properties.setScrollMetric( QScrollerProperties::HorizontalOvershootPolicy, overshoot_policy );
                            QVariant frame_rates = QVariant::fromValue< QScrollerProperties::FrameRates >( QScrollerProperties::Fps60 );
                            properties.setScrollMetric( QScrollerProperties::FrameRate, frame_rates );
                            QScroller::scroller( your widget )->setScrollerProperties( properties );
                        
                        P 1 Reply Last reply
                        1
                        • mrjjM mrjj

                          @Publicnamer
                          Hi
                          Yes, cells that are not allocated returns a NULL ptr for item() so it wont waste ram as such but
                          creating millions of items will take time.

                          So for huge models, often a custom model is used where the internal data structure fits the demand for such a huge amount of rows/items.

                          But what will work best depends on what you actually need to do.

                          artwawA Offline
                          artwawA Offline
                          artwaw
                          wrote on last edited by
                          #12

                          @Publicnamer out of curiosity - why bother with custom model when you can choose the path of least effort and employ QSqlTableModel (or derive something from QIdentityProxyModel) with Sqlite? With Qt you can instantiate in-memory db or, if during your project you discover that memory becomes an issue, quickly drop it from memory to disk?
                          Sqlite is lightning fast.
                          Sure, it requires a bit of thinking ahead (sorting, potential delegates for the table view) but in my experience all "convenience" item views are simply too much of a problem.

                          For more information please re-read.

                          Kind Regards,
                          Artur

                          1 Reply Last reply
                          1
                          • JoeCFDJ JoeCFD

                            @Publicnamer

                                QScrollerProperties properties = QScroller::scroller( your widget )->scrollerProperties();
                                QVariant overshoot_policy = QVariant::fromValue< QScrollerProperties::OvershootPolicy >( QScrollerProperties::OvershootAlwaysOff );
                                properties.setScrollMetric( QScrollerProperties::VerticalOvershootPolicy, overshoot_policy );
                                properties.setScrollMetric( QScrollerProperties::HorizontalOvershootPolicy, overshoot_policy );
                                QVariant frame_rates = QVariant::fromValue< QScrollerProperties::FrameRates >( QScrollerProperties::Fps60 );
                                properties.setScrollMetric( QScrollerProperties::FrameRate, frame_rates );
                                QScroller::scroller( your widget )->setScrollerProperties( properties );
                            
                            P Offline
                            P Offline
                            Publicnamer
                            wrote on last edited by
                            #13

                            @JoeCFD That seems to have no effect on my QTableWidget. I set the policy to OvershootAlwaysOn.
                            When I scroll using the mouse's thumbwheel is still stops at the defined last row.

                            Is there a signal that I can catch to detect when scrolling has stopped?
                            Thanks.

                            JoeCFDJ 1 Reply Last reply
                            0
                            • P Publicnamer

                              @JoeCFD That seems to have no effect on my QTableWidget. I set the policy to OvershootAlwaysOn.
                              When I scroll using the mouse's thumbwheel is still stops at the defined last row.

                              Is there a signal that I can catch to detect when scrolling has stopped?
                              Thanks.

                              JoeCFDJ Offline
                              JoeCFDJ Offline
                              JoeCFD
                              wrote on last edited by JoeCFD
                              #14

                              @Publicnamer I am using it for tablewidget in my code to avoid overshooting. This piece of code works fine for me on Ubuntu.
                              https://www.qtcentre.org/threads/16937-QTableWidget-scrolling-to-bottom-of-the-table

                              1 Reply Last reply
                              0
                              • SGaistS SGaist

                                Hi,

                                You can check the visualRect of the last index. If it's valid then it means the index is shown.

                                P Offline
                                P Offline
                                Publicnamer
                                wrote on last edited by Publicnamer
                                #15

                                @SGaist said in Infinite rows in QTableWidget?:

                                You can check the visualRect of the last index. If it's valid then it means the index is shown.

                                OK yes I can listen for the vertical scrollbar's valueChanged signal and check for the visualRect there.

                                P 1 Reply Last reply
                                0
                                • P Publicnamer

                                  @SGaist said in Infinite rows in QTableWidget?:

                                  You can check the visualRect of the last index. If it's valid then it means the index is shown.

                                  OK yes I can listen for the vertical scrollbar's valueChanged signal and check for the visualRect there.

                                  P Offline
                                  P Offline
                                  Publicnamer
                                  wrote on last edited by Publicnamer
                                  #16

                                  @Publicnamer Actually that doesn't work, because all rows have valid visualItemRect's.

                                      QRect rect = mytable->visualItemRect (item);
                                      if (rect.isValid()) { /* always true */ }
                                  

                                  The only solution I see is to use itemAt to find out what's at the bottom of the table.

                                  1 Reply Last reply
                                  0
                                  • P Publicnamer

                                    Is there a way to tell QTableWidget to support infinite rows?

                                    If not, how could I detect when the user scrolls to the last row, in order to automatically add more for the user?

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by JonB
                                    #17

                                    @Publicnamer
                                    It depends just what you want, what is in your model, and whether you know how much is in the backing model.

                                    Your question seems to relate to paging the data, or something based off that. Rather than looking at visual rects --- especially if they don't work --- the alternative is to look at the scrollbar. That reflects how far through the data the user is.

                                    One possible implementation is given in Pagination in QtableWidget, @raven-worx's algorithmic outline there.

                                    I have seen others (unfortunately can't find references) where the algorithm is to maintain the scrollbar height such that there is always a "gap" at the bottom which the user can scroll into, and that fires a fetch of more data and recalibration of the scrollbar, which still has a "gap" at the bottom. Think of when you use an application which produces large or endless output, like a web page receiving more and more data or showing photos where more and more are to come (e.g. some tumblr pages). The scrollbar always allows the user to scroll some more. @raven-worx's suggestion could be adapted to that.

                                    If you Google for stuff involving QTableWidget or QTableView and pagination you may find some useful code/ideas.

                                    1 Reply Last reply
                                    2

                                    • Login

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