Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ScrollView: Scroll TextEdit to the End
Qt 6.11 is out! See what's new in the release blog

ScrollView: Scroll TextEdit to the End

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.5k Views 1 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.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by
    #1

    Hi,

    I have a TextEdit which I use in a ScrollView:

    ScrollView {
                    id: view
                    anchors.fill: parent
                    wheelEnabled: true
                    ScrollBar.vertical.policy: ScrollBar.AlwaysOn
    
                    TextEdit {
                        id: t
                        focus: true
                        anchors.fill: parent
                        text: root.log
                        readOnly: true
                        font.pointSize: 10
                        font.family: monospaceFont.name
                        selectByMouse: true
                    }
                }
    

    how can I automatically scroll to the end if the text root.log is updated? I mean I know I can use onLogChanged, put don't know how to set the scroll position.

    T 1 Reply Last reply
    0
    • M maxwell31

      Hi,

      I have a TextEdit which I use in a ScrollView:

      ScrollView {
                      id: view
                      anchors.fill: parent
                      wheelEnabled: true
                      ScrollBar.vertical.policy: ScrollBar.AlwaysOn
      
                      TextEdit {
                          id: t
                          focus: true
                          anchors.fill: parent
                          text: root.log
                          readOnly: true
                          font.pointSize: 10
                          font.family: monospaceFont.name
                          selectByMouse: true
                      }
                  }
      

      how can I automatically scroll to the end if the text root.log is updated? I mean I know I can use onLogChanged, put don't know how to set the scroll position.

      T Offline
      T Offline
      Tom_H
      wrote on last edited by
      #2

      @maxwell31 Instead of using a ScrollView you could use a Flickable with attached ScrollBar and then manually set the position of the ScrollBar in your onLogChanged handler (e.g. sb.position = 1.0)

      Flickable {
        //...
        TextEdit {
          //...
        }
        ScrollBar.vertical: ScrollBar {id: sb}
      }
      
      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxwell31
        wrote on last edited by
        #3

        Thanks. Yes, that should work. Flickable seems to have the side effect, that it is not possible anymore to select text in my TextEdit, which is also a necessary requirement. Is there a way to change this?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxwell31
          wrote on last edited by
          #4

          But I will make a bigger question with the detailed requirements

          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