[SOLVED] TextArea scroll events



  • 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
    }

  • Moderators

    @beemaster Try this:

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


  • 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
                }
            }
        }
    }

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.