在Item
您的文档中可以找到以下内容:
注意:使用Text或TextEdit的implicitWidth并显式设置宽度会导致性能下降,因为必须对文本进行两次布局。
因此,我不应该这样写:
Text {
width: implicitWidth
text: 'my text defines the width'
}
这意味着,如果我不通过其他方式设置宽度,则无法有意义地锚定到Text
。
我想知道是否同样的性能损失适用于此结构:
Item {
id: myAnchorableTextBoundingBox
width: myText.implicitWidth
height: myText.implicitHeight
Text {
id: myText
text: 'my text defines the width'
}
}
还是这是该用例的可能解决方法?
它甚至允许我像这样绘制最大宽度:
Rectangle {
color: 'transparent'
border.color: 'red'
width: myText.width + 2
height: myText.height + 2
}
Rectangle {
id: myAnchorableTextBoundingBox
y: 1
x: 1
border.color: 'black'
width: myText.truncated ? myText.width : myText.implicitWidth
height: myText.implicitHeight
Text {
id: myText
text: 'my text defines the width until it elides, then the width is used as limit'
elide: Text.ElideRight
width: 200
}
}
Component
如果可以确定的话,我将立即对此作出解释,不会有(太大)的罚款。
这种解决方法应该可以正常工作。如文档所述,性能损失也是设置宽度时的一个问题:
使用隐式宽度[...]并显式设置宽度会导致性能下降
在这种情况下,你只能读取implicitWidth
性能,而不是再设定width
的的Text
元素,因此警告不适。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句