【发布时间】:2018-04-25 18:29:47
【问题描述】:
我有一个 QML TextItem,其中的文本是动态设置的。我无法确定文本的宽度,因为文本可以包含任意数量的字符。 我需要在它旁边放置另一个文本项。 那么当我们无法确定文本的宽度时如何锚定到文本项的右侧,因为文本可以随时增长。不允许使用 Wrap 或 Elide
例如:
Text
{
id: distance
width: //dont know what to provide
font.bold: true
verticalAlignment:Text.AlignBottom
horizontalAlignment:Text.AlignLeft
maximumLineCount: 1
onTextChanged:
{
console.log("$$$$$___Text is been changed:" + txt_distance.paintedWidth +" "+ paintedHeight)
}
anchors
{
bottom: parent.bottom
bottomMargin: 2
left: parent.left
leftMargin: 20
right: //Dont know what to give
}
和邻居项目
Text
{
id: address
font.bold: true
verticalAlignment:Text.AlignBottom
horizontalAlignment:Text.AlignLeft
maximumLineCount: 1
anchors
{
bottom: parent.bottom
bottomMargin: 2
left: distance.right <-- Please help
right: parent.right
rightMargin: 20
}
}
【问题讨论】: