Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Text rendering
Forum Updated to NodeBB v4.3 + New Features

Text rendering

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jankes
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      favoritas37
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jankes
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          favoritas37
          wrote on last edited by
          #4

          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();
          }
          

          }
          @

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jankes
            wrote on last edited by
            #5

            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 :/

            1 Reply Last reply
            0
            • F Offline
              F Offline
              favoritas37
              wrote on last edited by
              #6

              ...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...

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jankes
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved