Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    QTAbleView Not scrolling

    General and Desktop
    4
    10
    5617
    Loading More Posts
    • 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
      deepakkakkeel last edited by

      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 Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 0
          • D
            deepakkakkeel last edited by

            QT4 and centOS

            1 Reply Last reply Reply Quote 0
            • raven-worx
              raven-worx Moderators last edited by

              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 Reply Quote 0
              • D
                deepakkakkeel last edited by

                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 Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  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 Reply Quote 0
                  • C
                    ChrisW67 last edited by

                    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 Reply Quote 0
                    • D
                      deepakkakkeel last edited by

                      @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 Reply Quote 0
                      • C
                        ChrisW67 last edited by

                        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 Reply Quote 0
                        • First post
                          Last post