Text rendering



  • Hi. I have a problem. I'm developing animation of text: scrooling it from left to right (like in banner example from demos) and when the text is getting longer there is an increase of CPU usage (I guess that is becouse QML is rendering all text not only the visible part). So my question is: is there a way to limit rendering only to visible part not the whole text?



  • You can place the Text element in a Rectangle element. The Rectangle will have the property clip set to true. That way the Rectangle will define the visible area where the text will be shown and since the clip is set to true all the rest of the text will not be visible.

    Further more this will help you with the animation because you will be able to move the Text element inside the Rectangle creating a scroll animation by simply increasing/decreasing the x value of the Text.



  • I have already done the animation the way you said and the text is not visible outside the screen and still there is the problem.



  • How long is your long text?

    Also which platform are you targeting?

    For example i tested the following code on my Nokia 701 (1.3GHz CPU) and it goes till 20% of CPU usage when it runs.

    @
    Page {
    id: mainPage
    Text {
    id: txt
    x:0
    text: qsTr("You can place the Text element in a Rectangle element. The Rectangle will have the property clip set to true. That way the Rectangle will define the visible area where the text will be shown and since the clip is set to true all the rest of the text will not be visible.Further more this will help you with the animation because you will be able to move the Text element inside the Rectangle creating a scroll animation by simply increasing/decreasing the x value of the Text.")
    color: platformStyle.colorNormalLight
    font.pixelSize: 20

        PropertyAnimation on x{
                id: animation
                duration: 4000
                from:0
                to: -txt.width;
        }
    }
    
    MouseArea{
        anchors.fill: parent
        onClicked: animation.start();
    }
    

    }
    @



  • I'm targeting embbeded linux but now I run it on Desktop Linux with Core 2 Duo 2.2GHz processor. My program with your text takes 70% of CPU! I paste the code:

    @import QtQuick 1.0

    Rectangle {
    id: screen

    property int pixelSize: screen.height * 1.25
    property color textColor: "lightsteelblue"
    property string text: qsTr("You can place the Text element in a Rectangle element. The Rectangle will have the property clip set to true. That way the Rectangle will define the visible area where the text will be shown and since the clip is set to true all the rest of the text will not be visible.Further more this will help you with the animation because you will be able to move the Text element inside the Rectangle creating a scroll animation by simply increasing/decreasing the x value of the Text.")
    
    width: 1280; height: 100
    color: "steelblue"
    
    Row {
        y: -screen.height / 4.5
    
       
        Text {
               x: 100
               id: text;
               font.pixelSize: screen.pixelSize;
               color: screen.textColor;
               text: screen.text
        }
        NumberAnimation on x { from: screen.width; to: -text.width; duration: text.width*5; loops: Animation.Infinite }
      
    }
    

    }@

    and main.cpp viewing fragment:

    @QApplication app(argc, argv);
    QDeclarativeView viewer;
    QApplication::setGraphicsSystem("opengl");

    viewer.setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer)));
    viewer.setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
    viewer.setAttribute(Qt::WA_OpaquePaintEvent);
    viewer.setAttribute(Qt::WA_NoSystemBackground);
    viewer.viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
    viewer.viewport()->setAttribute(Qt::WA_NoSystemBackground);
    
    viewer.setSource(QUrl::fromLocalFile("qml/banner.qml"));
    viewer.show();
    
    return app.exec();@
    

    I hope there is solution to that :/



  • ...well...after playing around with your code i found out 2 things.

    First, if you remove the double buffering the CPU usage drops down effectively. But at the same time if you have big font pixel size at your text, the animation will be awful.

    The strange thing is that the animation gets affected if the text pixel size goes over 63. The memory size needed to show each letter gets bigger (from 6 bits to 7)? Is this a bug of Qt?

    To summarize for your problem, by simply observing i saw that without the double buffering and with text pixel size smaller or equal to 63 you will be fine. Unfortunately i have no explanation to give you for this behavior since i don't have it.

    I hope it helps...



  • I tried your changes and this is what I got:

    • when I disabled double buffering nothing happend except scroll stopped running fluently
    • setting smaller font actualy did it's job (maybe qml has to rescale it somehow, that's why it's buffering the whole text)

    Another fing that I found out is that when I have richt text, despite of small font the CPU usage is high.

    But there is still no straight answer to the problem.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.