×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Foster City, CA
    Posts
    24

    Number of character of displayed text

    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.

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    210

    Re: Number of character of displayed text

    Hi,
    In qml/js you can just use the string length function;
    Code:
        Text {
            id: display
    onTextChanged:  {   
                var StrLen = someString.length
                if (Strlen > someLength){
                   callSomeFunction();
    }
    }
    See this for the js ref. HERE
    Cheers,
    Jon

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    Foster City, CA
    Posts
    24

    Re: Number of character of displayed text

    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 ";
            }
        }
    }

  4. #4
    Nokia Developer Moderator
    Join Date
    Jul 2006
    Location
    Tampere, Finland
    Posts
    13

    Re: Number of character of displayed text

    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

  5. #5
    Registered User
    Join Date
    Mar 2009
    Location
    Foster City, CA
    Posts
    24

    Re: Number of character of displayed text

    thanks comment.
    I just started to implement a derived class of QDeclarativeItem like QDeclarativeText to support some other functions.

Similar Threads

  1. Show Text Instead of Phone number
    By karimi28 in forum General Messaging
    Replies: 1
    Last Post: 2010-11-25, 13:39
  2. Replies: 9
    Last Post: 2009-07-10, 13:56
  3. Number of rows of text displayed?
    By sridhar270 in forum General Development Questions
    Replies: 0
    Last Post: 2006-07-07, 07:55
  4. Replies: 1
    Last Post: 2004-02-12, 10:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×