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] List of visible rows in the viewport of QTableView
QtWS25 Last Chance

[SOLVED] List of visible rows in the viewport of QTableView

Scheduled Pinned Locked Moved General and Desktop
qtableviewviewport
7 Posts 3 Posters 9.4k 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.
  • S Offline
    S Offline
    Sam
    wrote on 15 Apr 2015, 07:48 last edited by Sam
    #1

    Hi,

    Is there anyway I can get the list of visible rows in the viewport of QTableView. Currently in the viewportEvent() of QTableView I can get the firstRow and the lastRow by using

    QModelIndex firstRowIndex = indexAt(QPoint(viewport()->rect().x()+5,viewport()->rect().y()+5));
    QModelIndex lastRowIndex = indexAt(QPoint(viewport()->rect().x()+5,viewport()->rect().height()-5));
    

    The requirement is to iterate/update something specific to the visible Rows in the viewport. If the some rows between the first/last row are hidden then I cannot use a for loop which will consume more time (e.g firstRow = 10, lastRow = 9500; )

    Regards
    Sam

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 15 Apr 2015, 23:08 last edited by
      #2

      Hi,

      IIRC, you can use visualRect to build that list.

      Hope it helps

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on 19 Apr 2015, 06:41 last edited by
        #3

        Hi SGaist,

        Thanks for your reply, with visualRect I need to pass the QModelIndex. In order to get the list of rows/items in the viewport of the tableView I now calculate using the height eg.

        int height = 0;
        while (height < viewport()->rect().height())  // viewport() of tableView
        {
          qDebug() << indexAt(QPoint(viewport()->rect().x(),height)).row());
          height += 25;
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 19 Apr 2015, 21:04 last edited by
          #4

          Are you sure about 25 ? You have to be sure that your rows are 50px high otherwise you might miss some

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on 20 Apr 2015, 11:31 last edited by
            #5

            Yes, this approach is temporary and I too don't like to do it this way. In fact for my requirement this does not make any difference even if I get the list of rows in the visible viewport(). I'll try to explain in brief what I am trying to achieve.

            I came across an article : Widgets on a header which works perfect for a horizontalHeaderView and also so a verticalHeaderView with few rows. Currently I am implementing the same for a VerticalHeaderView where I have a panel of buttons (eg add/delete) when we click on these button it add/delete a row.

            The only issue right now is performance, if the model is filled with a lot of rows then creating new panels is a time consuming process. My initial idea was to create the instance of these panel only for the visible rows in the viewport but it creates a lag/flickering when the viewport gets updated while scrolling the tableView.

            Another approach is to paint/render a fake panel and create a new instance when the mouse hover/enter the verticalHeader (don't know if this is even possible, with tableView cells this is easy to implement with delegate).

            Thanks for your time !

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 20 Apr 2015, 23:11 last edited by
              #6

              What do you need to render exactly ?

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alex_malyu
                wrote on 21 Apr 2015, 00:00 last edited by
                #7

                Are you sure indexAt() for every row is not slower then just iterating between indexes and checking that row is not hidden?

                1 Reply Last reply
                0

                7/7

                21 Apr 2015, 00:00

                • Login

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