Search code examples
word-wrapqmlqt-quicktextedit

QML: Simple word wrap with TextEdit element?


I'm just a beginner to QML and I wanted to make a simple example, which contains just one Rectangle with a TextEdit element:

import QtQuick 1.0

Rectangle {
    width: 400; height: 400
    color: "lightblue"

    TextEdit {
        x: 50; y: 100; width: 300; height: 300
        text: "editable text editable text editable text editable text "
        font.family: "Helvetica"; font.pixelSize: 32
    }
}

The idea here is to just have a few lines displayed that the user can change or add. I just would like it to display it as multiple word-wrapped lines instead of just on a single line. I don't even need a scrollbar. Since TextEdit does not have a WrapMode property, how can I do this? :-(

Thanks! Nina


Solution

  • TextEdit has a wordWrap property. See http://doc.qt.nokia.com/4.7/qml-textedit.html#wrapMode-prop.

    if you add

    wrapMode: TextEdit.WordWrap
    

    to the TextEdit component the text is wrapped to multiple lines.