I am trying to achieve an element which is vertically and horizontally centered on the page, has padded margins, and elements inside it are equally spaced and centered & wrapped (if needed). So in essence I'm trying to achive something like this:
But unfortunately, when the screen shrinks, the text doesn't preserve padding, nor stars to wrap.
Ideally I'd want a one unit padding around both paragraphs of text & one unit spacing between the two paragraphs and all of them centred/wrapped.
I've tried calculating & setting width/height properties, but they didn't do anything.
Here is my code:
Tab {
objectName: "Tab2"
title: i18n.tr("Title")
page: Page {
anchors.fill: parent
Item {
anchors.centerIn: parent
Text {
id: text1
text: "orem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in mollis purus"
wrapMode: Text.Wrap
width: parent.width
horizontalAlignment: Text.AlignHCenter
}
Text {
text: "Etiam sagittis fringilla quam, eget accumsan libero pulvinar ac."
wrapMode: Text.Wrap
width: parent.width
anchors {
top: text1.bottom
topMargin: units.gu(2)
}
horizontalAlignment: Text.AlignHCenter
}
}
}
}
Your Item doesn't have width and height defined, so it takes the height of the children and the wrapping breaks.
This code probably does what you want, but maybe you need to tweak some margins:
If you want to keep the two Text items separate, you can also use a Column: