Hi,

This should do the trick:

    SilicaFlickable {
        id: flickable
        anchors.fill: parent
        contentHeight: textAreaLog.height
        contentY: Math.max(0, contentHeight - height)
        TextArea {
            id: textAreaLog
            readOnly: true
            text: "Test"
            width: flickable.width
        }
    }

The contentY binding is the one that keeps the last line visible (but has some 
annoying side effects if you want to scroll the content manually - fixing that 
is left as home work :) )

---
Sami Kananoja

________________________________________
From: devel-boun...@lists.sailfishos.org [devel-boun...@lists.sailfishos.org] 
on behalf of Dirk Zimmermann [me+sailfis...@dirkz.com]
Sent: Friday, January 02, 2015 9:58 AM
To: devel@lists.sailfishos.org
Subject: [SailfishDevel] Read-only TextArea: Always keep the lines added        
last visible

Hi all,

I was trying to use a TextArea as a UI-visible debug log, so I can see
connection error details while I'm out using my app. The basic principle
is that the python code (pyotherside) will make a server request and
send detailed answers to the text area, which displays them. Everything
works find, except the text area doesn't auto scroll to the end when
there is more content than fits on the page. autoScrollenabled seems to
mean something entirely different, selectionStart start seems to be
read-only. I have put up an example that demonstrates, at the end of the
mail.

Does anyone know of the magic incantations needed to make sure the
latest lines are always visible?

import QtQuick 2.0
import Sailfish.Silica 1.0

Page {
    id: textAreaLogExample

    SilicaFlickable {
        TextArea {
            id: textAreaLog
            readOnly: true
            text: "Test"
            autoScrollEnabled: true
        }
    }

    Timer {
        interval: 500; running: true; repeat: true
        onTriggered: {
            textAreaLog.text += "\n" + new Date().getUTCSeconds() + " Log"
        }
    }
}
_______________________________________________
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
_______________________________________________
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Reply via email to