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. TextArea won't scroll up when new text added.
Forum Updated to NodeBB v4.3 + New Features

TextArea won't scroll up when new text added.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 2.4k Views 1 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.
  • Steve FallowsS Offline
    Steve FallowsS Offline
    Steve Fallows
    wrote on last edited by
    #1

    I have the following implementation of a simple console type window for scrolling text output:

    Rectangle {
        id: consoleOutput_rectangle
        x: 40
        y: 112
        width: 720
        height: 400
        color: "#ffffff"
    
        Flickable {
            id: flickable
            anchors.fill: parent
            contentWidth: consoleOutput_textArea.width
            contentHeight: consoleOutput_textArea.height
            flickableDirection: Flickable.VerticalFlick
            clip: true
    
            TextArea.flickable:
            TextArea {
                id: consoleOutput_textArea
                objectName: "ConsoleTextObject"
                anchors.fill: parent
                text: qsTr("Initial Text Area Text")
                wrapMode: Text.WordWrap
                onTextChanged: {
                    console.log("OnTextChanged - height: " + consoleOutput_textArea.height + " " + flickable.height)
                    if (consoleOutput_textArea.height > flickable.height) {
                        flickable.contentY = consoleOutput_textArea.height - flickable.height
                        console.log("OnTextChanged - contentY changed to: " + flickable.contentY)
                    }
                }
                function appendText(additionalText) {
                    text += additionalText
                }
            }
            ScrollBar.vertical: ScrollBar {}
        }
    }
    

    If I use this to add text at the bottom from C++ code, using the append function of TextArea:

        QMetaObject::invokeMethod(mConsoleTextObject, "append", Q_ARG(QString, additionalText));
    

    it works except that append is line oriented, meaning it inserts a line feed after every line. So I added the appendText function seen in the QML above and invoke it like this:

        QMetaObject::invokeMethod(mConsoleTextObject, "appendText", Q_ARG(QVariant, additionalText));
    

    It works, except that now the text does not scroll up when it reaches the bottom. The console.log statements indicate that the onTextChanged functions is being called and the contentY number seems to be correct.

    Am I missing some kind of repaint/update that's built into the native append? (I tried to call flickable.update() but it complained that the is no content in the flickable.)

    1 Reply Last reply
    0
    • atmel.ruA Offline
      atmel.ruA Offline
      atmel.ru
      wrote on last edited by
      #2

      Hi,
      please post full your qml code, I have tried it without problem.

      1 Reply Last reply
      0
      • jpnurmiJ Offline
        jpnurmiJ Offline
        jpnurmi
        wrote on last edited by
        #3

        It is mentioned in the docs:

        Appends a new paragraph with text to the end of the TextEdit.

        In order to append without inserting a new paragraph, call myTextEdit.insert(myTextEdit.length, text) instead.

        Steve FallowsS 1 Reply Last reply
        1
        • jpnurmiJ jpnurmi

          It is mentioned in the docs:

          Appends a new paragraph with text to the end of the TextEdit.

          In order to append without inserting a new paragraph, call myTextEdit.insert(myTextEdit.length, text) instead.

          Steve FallowsS Offline
          Steve FallowsS Offline
          Steve Fallows
          wrote on last edited by
          #4

          @jpnurmi - Thanks, that solved my problem.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved