3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

私の場合は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かそれに相当するプロパティが設定されてるか確認するといいと思う

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?