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. QListView ScrollToBottom doesn't scroll to the very end
Forum Updated to NodeBB v4.3 + New Features

QListView ScrollToBottom doesn't scroll to the very end

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.4k Views 2 Watching
  • 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.
  • KodzghlyCZK Offline
    KodzghlyCZK Offline
    KodzghlyCZ
    wrote on last edited by
    #1

    Hello
    I want to achieve the 'Auto scroll' effect on QListView component, currently I am using scrollToBottom() function to get to the very end, but it always stays a little bit above the complete end of the list, see the image attached below.
    I think there might be some feature in the QtDesigner that I haven't discovered yet, but I was not able to figure out how to scroll to the very end, so the bottom line doesn't get clipped this bad.
    I am using Python with PySide6 and I am importing the ui file converted to the .py file using pyside6-uic tool.

    Thanks to anybody answering, I really appreciate any piece of help, since I'm fairly new to the whole Qt stuff, but I like to learn and I hope my question is just not completely stupid.

    The image:
    issue.png

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

      Hi and welcome to devnet,

      Shouldn't you rather use scrollTo using QAbstractItemView::PositionAtBottom ?

      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
      • KodzghlyCZK Offline
        KodzghlyCZK Offline
        KodzghlyCZ
        wrote on last edited by
        #3

        I don't know if I'm doing anything wrong, but the code implemented throws me an exception

        TypeError: 'PySide6.QtWidgets.QListView.scrollTo' called with wrong argument types:
          PySide6.QtWidgets.QListView.scrollTo(ScrollHint)
        Supported signatures:
          PySide6.QtWidgets.QListView.scrollTo(PySide6.QtCore.QModelIndex, PySide6.QtWidgets.QAbstractItemView.ScrollHint = PySide6.QtWidgets.QAbstractItemView.ScrollHint.EnsureVisible)
        

        The line I added looks like this:

        self.ui.phpConsole.scrollTo(QAbstractItemView.PositionAtBottom)
        

        I just changed the line mentioned previously with this one, but the error shows up.

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

          You are missing the index argument.

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

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            You are missing the index argument.

            S Offline
            S Offline
            sebwr
            wrote on last edited by
            #5

            @SGaist

            Hey I tried it by creating an QModelIndex based on the current data of the model:

            class LogModel(QAbstractListModel):
                ...
                def log(self, message: str):
                    self.experiment_logs.append(message)
                    self.layoutChanged.emit()
                    current_index = self.createIndex(len(self.experiment_logs)-1, 0)
                    self._list_view.scrollTo(current_index, QAbstractItemView.PositionAtBottom)
            

            the following QModelIndex is returned in the last step:
            <PySide6.QtCore.QModelIndex(100,0,0x0,LogModel(0x3d8ad00)) at 0x7f06c843a280>
            where the "100" matches the length - 1 of the list which is the data structure behind the LogModel.

            But when I call scrollTo, as suggested by you, nothing happends.

            I am also tried the following (Which should be wrong, because the QModelIndex should also start at zero?):

            current_index = self.createIndex(len(self.experiment_logs), 0)
            

            Any further thoughts?

            SGaistS 1 Reply Last reply
            0
            • S sebwr

              @SGaist

              Hey I tried it by creating an QModelIndex based on the current data of the model:

              class LogModel(QAbstractListModel):
                  ...
                  def log(self, message: str):
                      self.experiment_logs.append(message)
                      self.layoutChanged.emit()
                      current_index = self.createIndex(len(self.experiment_logs)-1, 0)
                      self._list_view.scrollTo(current_index, QAbstractItemView.PositionAtBottom)
              

              the following QModelIndex is returned in the last step:
              <PySide6.QtCore.QModelIndex(100,0,0x0,LogModel(0x3d8ad00)) at 0x7f06c843a280>
              where the "100" matches the length - 1 of the list which is the data structure behind the LogModel.

              But when I call scrollTo, as suggested by you, nothing happends.

              I am also tried the following (Which should be wrong, because the QModelIndex should also start at zero?):

              current_index = self.createIndex(len(self.experiment_logs), 0)
              

              Any further thoughts?

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi and welcome to devnet,

              What does _list_view do in that model ? That's not its place.
              Also, emitting layoutChanged for adding a row of data is wrong. There are two signals to signify that you are adding new data and when you are done, use them.

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

              S 1 Reply Last reply
              1
              • SGaistS SGaist

                Hi and welcome to devnet,

                What does _list_view do in that model ? That's not its place.
                Also, emitting layoutChanged for adding a row of data is wrong. There are two signals to signify that you are adding new data and when you are done, use them.

                S Offline
                S Offline
                sebwr
                wrote on last edited by sebwr
                #7

                @SGaist

                Yes the _list_view was at the wrong place. I am now emitting a signal to the correct place.

                I got it working with:

                LogModel:

                def log(self, message: str):
                    self.experiment_logs.append(message)
                    top_index = self.createIndex(self.rowCount()-2, 0)
                    bottom_index = self.createIndex(self.rowCount()-1, 0)
                    self.dataChanged.emit(top_index, bottom_index)
                
                    self.signal.scroll_list_view.emit()
                

                Main:

                self.log_model.signal.scroll_list_view.connect(
                    lambda: self.list_view_log.scrollToBottom()
                )
                

                So I guess the scrollToBottom works fine if the correct Signal is emitted?

                SGaistS 1 Reply Last reply
                0
                • S sebwr

                  @SGaist

                  Yes the _list_view was at the wrong place. I am now emitting a signal to the correct place.

                  I got it working with:

                  LogModel:

                  def log(self, message: str):
                      self.experiment_logs.append(message)
                      top_index = self.createIndex(self.rowCount()-2, 0)
                      bottom_index = self.createIndex(self.rowCount()-1, 0)
                      self.dataChanged.emit(top_index, bottom_index)
                  
                      self.signal.scroll_list_view.emit()
                  

                  Main:

                  self.log_model.signal.scroll_list_view.connect(
                      lambda: self.list_view_log.scrollToBottom()
                  )
                  

                  So I guess the scrollToBottom works fine if the correct Signal is emitted?

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  When you add data, there's a begin/endInsertRows pair of function that you should call. Their a responsible for notifying the view that things are changing with regard to the amount of the data.

                  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

                  • Login

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