Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Scroll TextArea to end



  • Hello,

    I want to make a chatmessenger-like surface. To display the incoming strings I use a TextArea.
    The problem is, if the TextArea is full with lines it don't scoll. I searched around but I didn't found a solution how to set the scrolling position.
    Additionally if I scroll manually down to the new messages, the TextArea jumps to the top with every new incoming message.

    Here my qml-File:

    ColumnLayout {
        id: root
    
        ConfigChatVM {
            id: configChatVM
        }
    
        TextArea {
            readOnly: true
            Layout.fillHeight: true
            Layout.fillWidth: true
            text: configChatVM.history
        }
    
        RowLayout {
            Layout.fillHeight: true
            Layout.fillWidth: true
    
            TextInput {
                id: input
                Layout.fillHeight: true
                Layout.fillWidth: true
                font.pixelSize: 12
                onEditingFinished: {
                    if (activeFocus)
                    {
                        configChatVM.sendMessage(text)
                        text = ""
                    }
                }
            }
    
            Button {
                text: qsTr("Button")
                Layout.fillHeight: true
                Layout.fillWidth: false
                onClicked: {
                    configChatVM.sendMessage(input.text)
                }
            }
        }
    }
    
    

  • Moderators



  • No because I want to use property-binding. I will try that but there must me a solution for someone using property-binding.


  • Moderators

    I haven't come across any built-in property will always display TextArea with contents scrolled to Bottom.
    Another way would be to do some math and set TextArea's flickableItem.contentY.


Log in to reply