Help us understand the problem. What is going on with this article?

Text/Labelでwordwrapがうまくいかずに文字がはみ出してしまう時の対処方法

More than 5 years have passed since last update.

私の場合はQtQuick.LayoutsのRow/ColumnLayoutを使って区切ったcellの中にテキストを入れようとした時に起こった

main.qml
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1

ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480

    property string loremIpsum:
        "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor "+
        "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor "+
        "incididunt ut labore et dolore magna aliqua.\n Ut enim ad minim veniam, quis nostrud "+
        "exercitation ullamco laboris nisi ut aliquip ex ea commodo cosnsequat. ";

    RowLayout {
        anchors.fill: parent
        Rectangle {
            Layout.preferredWidth: parent.width / 4
            Layout.fillHeight: true
            color: "red"
        }
        Label {
            text: loremIpsum
            wrapMode: Text.Wrap
        }
        Rectangle {
            Layout.preferredWidth: parent.width / 3
            Layout.fillHeight: true
            color: "blue"
        }
    }
}

window.png

Text/Labelは何かしらの方法でwidthを設定してやらないとはみ出すようだ
上の場合はLabelLayout.fillWidth: trueを追加するとうまくいく

main.qml
        Label {
            Layout.fillWidth: true
            text: loremIpsum
            wrapMode: Text.Wrap
        }

window2.png

wordwrapできずにはみ出すときはwidthかそれに相当するプロパティが設定されてるか確認するといいと思う

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away