setting wrapMode property of Text in ScrollView

1.2k views Asked by At

I wrote QML like this:

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1

import App 0.1

ApplicationWindow {
    id: appWindow
    visible: true
    width: 300
    height: 500

    ColumnLayout {
        ScrollView {
            ColumnLayout {
                Text {
                    width: 250
                    text: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
                    wrapMode: Text.WrapAnywhere
                }
            }
        }
    }

    AppController {
        id: controller
    }
}

and this is the visual outcome:

enter image description here

I want to wrap Text inside ScrollView. I've tried many patterns but I failed to achieve the desired result. How can I do that?

1

There are 1 answers

1
qCring On BEST ANSWER

Just remove ColumnLayout, that's not necessary here. This works for me (if that's what you're looking for):

import QtQuick 2.2
import QtQuick.Controls 1.3

ApplicationWindow {
  id: appWindow
  visible: true
  width: 300
  height: 500

  ScrollView {
    anchors.fill: parent

    Column {
      Repeater {
        model: 10
        delegate: Text {
          width: appWindow.width - 50
          text: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
          wrapMode: Text.WrapAnywhere
        }
      }
    }
  }
}

Try to avoid fixed sizes where possible. In your case the Text doesn't react to window resizing. Also when providing code snippets, just remove specific fragments like your AppController for example (even if it's no big deal in this case but it's easier for anyone to run and test your code) :)

Hope this helps!