Hi,
If I set a long text string to small text area, it will be clipped.
How can I know the number of character for displayed text string?
I'd like to add next/ prev button for this text area and add paging function.
Hi,
If I set a long text string to small text area, it will be clipped.
How can I know the number of character for displayed text string?
I'd like to add next/ prev button for this text area and add paging function.
Hi,
In qml/js you can just use the string length function;
See this for the js ref. HERECode:Text { id: display onTextChanged: { var StrLen = someString.length if (Strlen > someLength){ callSomeFunction(); } }
Cheers,
Jon
It seems that string.length returns the length of original string not clipped string.
I just write the following code.
After some clicked, the text will be clipped, but the length is still increasing.
I'd like to know the length of clipped string.
Code:import QtQuick 1.0 Rectangle { width: 360 height: 360 Rectangle { id: textArea anchors.centerIn: parent width: 100 height: 60 color: "yellow" } Text { id: text anchors.fill: textArea text: "Hello World" clip: true wrapMode: Text.WordWrap onTextChanged: { console.log("length:" + text.length); } } MouseArea { anchors.fill: parent onClicked: { text.text += "Hello "; } } }
Not really sure if there is an easy way to accomplish that using QML+JS, so you may need to implement it in C++.
With Text.paintedWidth you can get the width of the string that is painted, but that of course doesn't help in getting the number of characters drawn:
Code:import QtQuick 1.0 Rectangle { width: 360 height: 360 Rectangle { id: textArea anchors.centerIn: parent width: 100 height: 60 color: "yellow" } Text { id: mytext anchors.fill: textArea text: "Hello" clip: true wrapMode: Text.WordWrap onTextChanged: { console.log(mytext.paintedWidth) } } MouseArea { anchors.fill: parent onClicked: { mytext.text += "Hello "; } } }
- Late
thanks comment.
I just started to implement a derived class of QDeclarativeItem like QDeclarativeText to support some other functions.