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. [SOLVED] TextArea scroll events
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] TextArea scroll events

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.0k 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.
  • B Offline
    B Offline
    beemaster
    wrote on last edited by beemaster
    #1

    Is there a way to know when TextArea scroll reached top/bottom? I want to implement dynamic text loading in chat, so when user scrolls to top, more text is added to the document. Something like this:

    import QtQuick.Controls 1.2
    
    TextArea {
          id: chat
          onScrolledToTop: text = loadMoreText() + text
    }
    
    p3c0P 1 Reply Last reply
    0
    • B beemaster

      Is there a way to know when TextArea scroll reached top/bottom? I want to implement dynamic text loading in chat, so when user scrolls to top, more text is added to the document. Something like this:

      import QtQuick.Controls 1.2
      
      TextArea {
            id: chat
            onScrolledToTop: text = loadMoreText() + text
      }
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @beemaster Try this:

      TextArea {
           flickableItem.onContentYChanged: console.log(flickableItem.atYEnd)
      }
      

      157

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beemaster
        wrote on last edited by
        #3

        import QtQuick 2.4
        import QtQuick.Window 2.2
        import QtQuick.Controls 1.3

        Window {
            visible: true
            width: 400
            height: 200
        
            TextArea {
                id: chat
                anchors.fill: parent
                property int threshold: 10
        
                text: "Current\ntext\n\\to\nmove\ndown\ndown\ndown
                       \ndown\ndown\ndown\ndown\ndown\ndown\ndown"
                Component.onCompleted: cursorPosition = text.length
        
        
                flickableItem.onContentYChanged: {
                    if(flickableItem.contentY <= threshold) {
                        var oldHeight = flickableItem.contentHeight
                        text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                                    sed do eiusmod tempor incididunt ut labore et dolore magna
                                    aliqua." + text
                        flickableItem.contentY = threshold + flickableItem.contentHeight - oldHeight  // leave flickable in old position
                    }
                }
            }
        }
        
        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