Search code examples
qmlqtquickcontrols2

QML TextArea won't scroll


I added a simple TextArea in my application. Unfortunately, I can't scroll through the text even if its contentHeight bypasses its height.
Here is the code:

import QtQuick 2.7
import QtQuick.Controls 2.0

ApplicationWindow {
    id: appWindow
    visible: true
    width: 480
    height: 640
    TextArea{
        anchors.fill: parent
        anchors.margins: 100
        wrapMode: TextEdit.Wrap
        Component.onCompleted: {
            console.log("width:", width)
            console.log("contentWidth:", contentWidth)
            console.log("height:", height)
            console.log("contentHeight:", contentHeight)
        }
        onTextChanged: {
            console.log("width:", width)
            console.log("contentWidth:", contentWidth)
            console.log("height:", height)
            console.log("contentHeight:", contentHeight)
        }
    }
}

Solution

  • TextArea is not scrollable by default, mainly to make it possible to have multi-line editors as part of a scrollable page without having nested Flickables, which often gives sub-optimal experience. In order to make a standalone TextArea scrollable, you can attach it to a Flickable as illustrated in the documentation.