[Qt-qml] Text eliding
Bo Thorsen
bo at fioniasoftware.dk
Tue Sep 6 10:08:23 CEST 2011
I'm trying to ellide a text item, but it's proving quite complicated.
I'm tempted to implement my own C++ based QML class that does this, but
it just seems silly.
The problem is that Text says it can only elide when you have set the
width, but I don't have that.
I have something like this:
Item {
width: parent.width
anchors.centerIn: parent
Text {
id: text1
text: ...
elide: Text.ElideRight
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.bold: true
}
Text {
id: text2
text: ....
}
}
(most anchors and stuff like that has been omitted)
So I want text1 to elide on the right side, when the combined text of
the two doesn't fit in the row. What I actually have here is a max width
which is parent.width - text2.width. In HTML, it would look like this:
"<center><bold>text1</bold>text2</center>", except that text1 should be
elided.
It might be that there is a way to set something like this on the text2
width:
width: max(font.textWidth(text), parent.width - text2.width)
But I haven't been able to figure out how to do that.
Any good ideas?
Bo Thorsen,
Fionia Software.
--
Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
More information about the Qt-qml
mailing list