[Interest] QML Text.contentWidth is never increasing

Jason H jhihn at gmx.com
Fri Oct 21 15:41:51 CEST 2016


> Jason H wrote:
> >Text {
> >	id: instructionText
> >	color: "white"
> >	text: instructionTextData
> >	width: contentWidth > parent.width *.9 ? parent.width *.9 : contentWidth
> >	font.pointSize: 16
> >	horizontalAlignment: Text.AlignHCenter
> >	anchors.horizontalCenter: parent.horizontalCenter }
> >
> >Where I want the text to be it's natural width up to 90% of the parent width, then wrap, but it only works when initially laying out and shrinking. 
> 
> I think I'm missing some use case, why bother setting the width to contentWidth?
> You anyway center the Text element and the text inside it so nothing prevents you from always setting it to parent.width *.9?
> The text will then still be centered inside the Text element, and the Text element centered in its parent.

Good idea. Visually it is the same, but not when you have a MouseArea that you only want to apply to the text.
[------------text-------------] (your solution, setting text align)
vs 
------------[text]------------- (my desired situtation, because there is another MouseArea behind it)
(Stuff in brackets is child MouseArea with anchors.fill:parent)

Also I'm not changing contentWidth. According to my interpretation of the docs, contentWidth should not change with a wrapMode set.




More information about the Interest mailing list