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. QTAbleView Not scrolling

QTAbleView Not scrolling

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 6.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.
  • D Offline
    D Offline
    deepakkakkeel
    wrote on last edited by
    #1

    HI,

    I have QTableView with so many rows in it Such that the last row wont be visible. Only first 10 rows are visible in the screen . For viewing others we need to scroll.
    I wanted to show the last row progrmatically. I use tableview->scrollTo(QModelIndex i) function. "i" is the model index of last row. But this is not working. May i know what is the reason and how to solve it?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      scrollTo() is the correct way to do it. So the problem must be somewhere else in your code...
      Maybe you call it too early? Show us some code please...

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

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

        Hi,

        Also, what version of Qt are you using and on what OS ?

        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
        • D Offline
          D Offline
          deepakkakkeel
          wrote on last edited by
          #4

          QT4 and centOS

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            and the code?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • D Offline
              D Offline
              deepakkakkeel
              wrote on last edited by
              #6

              TableModel *temp_model ;
              //TableModel has data in it.
              //element is the TableView

                  for(int i=0;i<temp_model->rowCount();i++) {
                      for(int j=0;j<temp_model->columnCount();j++) {
                         if(some condition to enter the function)
                          QModelIndex ii=temp_model->index(i,j);
                          element->scrollTo(ii);
                           }
                      }
                    }
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Please encode your code between coding tags.

                Are you sure element->scrollTo is called ?

                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
                • C Offline
                  C Offline
                  ChrisW67
                  wrote on last edited by
                  #8

                  If TableModel is derived from QSqlTableModel then you need to read about canFetchMore() and fetchMore() because rowCount() may not return the number of the last row in the table.

                  Also, it helps if you describe what "it doesn't work" actually means. What were you expecting, what did it actually do, what have you tried to fix it etc.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    deepakkakkeel
                    wrote on last edited by
                    #9

                    @TableModel *temp_model ;
                    //TableModel has data in it.
                    //element is the TableView
                    for(int i=0;i<temp_model->rowCount();i++) {
                    for(int j=0;j<temp_model->columnCount();j++) {
                    if(some condition to enter the function)
                    QModelIndex ii=temp_model->index(i,j);
                    element->scrollTo(ii);
                    }
                    }
                    } @

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      ChrisW67
                      wrote on last edited by
                      #10

                      The code you have posted will not compile. The if statement at line 6 terminates at line 7. At line 8 there is no variable called "ii" in scope (unless there is an "ii" at wider scope, in which case it may compile and not do what you expect). Line 11 does not have a matching "{" in the snippet.

                      Why are you trying to scrollTo() every single index in the table? If want the "bottom" of the table then you can get that directly:
                      @
                      QModelindex bottomLeft = model->index(model->rowCount() - 1, 0);
                      view->scrollTo(bottomLeft);
                      // OR
                      QModelindex bottomRight = model->index(model->rowCount() - 1, model->columnCount() - 1);
                      view->scrollTo(bottomRight);
                      @

                      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