Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    What's the fastest way to display some text in Qt?

    General and Desktop
    qlabel text rendering
    7
    29
    11801
    Loading More Posts
    • 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.
    • Wings
      Wings last edited by Wings

      I am developing an application where I need to display some text real fast. A precise timer issues a "draw string" command and a text is displayed for about 10-30 ms. So, I need a fast way to render text on the screen. I am currently using a QLabel, but it's not able to handle that speed, hence it fails to draw the text several times. The quality of the render is not very important. The text should just be readable, that's all. How can I get the desired speed? Or maybe, is there any way in which I can get good enough speed from QLabel?

      1 Reply Last reply Reply Quote 0
      • V
        vtduong last edited by

        Have you tried using a QTextBox instead?

        Or another way is two have two labels, have one show while the other disappears. it will give the impression that it's faster.

        Wings 1 Reply Last reply Reply Quote 0
        • Wings
          Wings @vtduong last edited by

          @vtduong What's QTextBox?? I couldn't find that in the documentation. I'm using Qt 5.4, by the way.

          JKSH 1 Reply Last reply Reply Quote 0
          • JKSH
            JKSH Moderators @Wings last edited by

            @Wings said:

            @vtduong What's QTextBox?? I couldn't find that in the documentation. I'm using Qt 5.4, by the way.

            I think he meant QLineEdit.

            Anyway, the Console will update text much faster than any widget.

            a text is displayed for about 10-30 ms.

            That's very short. May I ask why you want to update the text so quickly? Are you sure the user can read at that speed?

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            Wings 1 Reply Last reply Reply Quote 0
            • Wings
              Wings @JKSH last edited by

              @JKSH Thanks, but mine is a GUI application. And yeah, the text should be updated very quickly because it's about subliminal messages - at the border of conscious perception. Did that sound spooky? :D

              Anyway, I don't believe QLineEdit is any faster than QLabel. Is it?

              JKSH 1 Reply Last reply Reply Quote 0
              • JKSH
                JKSH Moderators @Wings last edited by

                @Wings said:

                @JKSH Thanks, but mine is a GUI application. And yeah, the text should be updated very quickly because it's about subliminal messages - at the border of conscious perception. Did that sound spooky? :D

                Sounds pretty cool! :D Psych experiment?

                Anyway, I don't believe QLineEdit is any faster than QLabel. Is it?

                I don't know, sorry; I've never tried updating text at that speed. But I'm guessing it wouldn't be faster. The best way to find out is to try it.

                Also try:

                • The Graphics View Framework, with QGraphicsSimpleTextItem
                • Qt Quick 2

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                Wings 1 Reply Last reply Reply Quote 1
                • Wings
                  Wings @JKSH last edited by Wings

                  @JKSH said:

                  Sounds pretty cool! :D Psych experiment?

                  LOL no! It'll be a self development application and I'll release it soon, for free!

                  The Graphics View Framework, with QGraphicsSimpleTextItem

                  I read that QGraphicsSimpleTextItem should be added to a QGraphicsScene. Looks pretty low-level. I hope things don't get very complicated there. I'm already very inclined to over-engineer things. Anyway, I'll give a shot. Thanks for the pointer (and also for imagining me doing some "Psych experiment" :D).

                  JKSH 1 Reply Last reply Reply Quote 0
                  • G
                    great Banned last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote -1
                    • KiwiJeff
                      KiwiJeff last edited by

                      Out of curiosity, but how are you actually measuring the time? It sounds like something I might want to check out myself.

                      Wings 1 Reply Last reply Reply Quote 0
                      • Wings
                        Wings @KiwiJeff last edited by

                        @KiwiJeff said:

                        Out of curiosity, but how are you actually measuring the time? It sounds like something I might want to check out myself.

                        Right now I'm using a Qt::PreciseTimer type QTimer. But, probably I'll move to one with <10ms resolution.

                        KiwiJeff 1 Reply Last reply Reply Quote 0
                        • Wings
                          Wings last edited by Wings

                          This post is deleted!
                          1 Reply Last reply Reply Quote 0
                          • JKSH
                            JKSH Moderators last edited by

                            @Wings said:

                            Oh! I wanted to close this thread, instead I deleted the question!!! Great.

                            Restored :)

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            1 Reply Last reply Reply Quote 0
                            • JKSH
                              JKSH Moderators @Wings last edited by JKSH

                              @Wings said:

                              I read that QGraphicsSimpleTextItem should be added to a QGraphicsScene. Looks pretty low-level.

                              Yes, people often use low-level tools in order to gain higher performance.

                              Also have a look at Qt Quick. It is GPU-accelerated, which might help.

                              Thanks for the pointer (and also for imagining me doing some "Psych experiment" :D).

                              You're welcome!

                              When I was a student, I earned a bit of pocket money signing up as a test subject for psych experiments, designed and run by psychology PhD students. Sound spooky? ;-) (those experiments often involved reacting to shapes and colours on a computer screen)

                              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                              Wings 1 Reply Last reply Reply Quote 1
                              • Wings
                                Wings @JKSH last edited by Wings

                                Reading http://code.woboq.org/qt5/qtbase/src/widgets/widgets/qlabel.cpp.html#273 (thanks @JKSH for the link) helped. Looks like doing setTextFormat(Qt::PlainText) prevents Qt from guessing the type of text (when it comes to milliseconds, everything counts).

                                @JKSH said:

                                Also have a look at Qt Quick. It is GPU-accelerated, which might help.

                                I'll try that soon. But, I've realized that I was making a very fundamental mistake in understanding my problem. The mistake is, my timer will anyway start only after the text is completely drawn (i.e. after setText() returns). So, the resolution of the timer is actually the crucial factor here. If the timer provides microsecond (or at least low-millisecond) resolution, accurately, the clear() slot will be called (almost) exactly after the required number of milliseconds. Then, the required subliminal behavior can be obtained. I hope I'm able to explain my mistake clearly. And I also hope someone else on Earth is benefited from this (Martians not allowed).

                                When I was a student, I earned a but of pocket money signing up as a test subject for psych experiments, designed and run by psychology PhD students. Sound spooky? ;-) (those experiments often involved reacting to shapes and colours on a computer screen)

                                This one really sounds a little spooky! :D

                                P.S.: I'm impressed by the friendliness of the Qt community. So, all my Qt questions will now be redirected from www.stackoverflow.com to forum.qt.io.
                                1 Reply Last reply Reply Quote 0
                                • Chris Kawa
                                  Chris Kawa Moderators last edited by Chris Kawa

                                  Spooky or not you can't really go faster than what the display can handle. Most consumer grade displays tick at (or around) 60Hz, which means one frame takes about 16.6ms. Updating any faster than that is just wasting CPU. A percentile of the users (like 3D Vision gamers or some graphics professionals) might have a higher frequency displays which ticks at around 100 or 120Hz, but they are extremely rare at best.

                                  Wings 1 Reply Last reply Reply Quote 1
                                  • Wings
                                    Wings @Chris Kawa last edited by

                                    @Chris-Kawa

                                    Thanks. That's something I didn't pay attention to. Then, I guess I should set the lower limit to something around 16ms (is 17ms safe enough?).

                                    1 Reply Last reply Reply Quote 0
                                    • Chris Kawa
                                      Chris Kawa Moderators last edited by Chris Kawa

                                      @Wings said:

                                      is 17ms safe enough?

                                      Absolutely not. Any fixed interval generally isn't. I intentionally said "or around". It's common for displays to refresh at 59.XX - 60.YY Hz.
                                      If you fix your interval at 17ms (assuming you can be that precise, which you generally can't anyway) you are ending at an update for example every 17/16.63 of frame. Of course the display won't wait for you if you're late like that, so even if you miss the refresh 0.0001ms you will skip a frame and you will see visible stutter or other artifacts.

                                      UI controls like line edits or labels are not designed to be high-frequency or latency free controls and as so they don't care that much to be "frame-perfect". They can skip a frame or two if they need more time to format their content (especially something like rich text).

                                      If you want high frequency display you should do your own painting. Eaither with classes mentioned by JKSH or simply drawing with QPainter in paintEvent. The general idea is you don't try to "chase" refresh rate of the display. Draw your stuff and schedule next update (read update() and repaint() docs and the differences). If you need to, you can check how much time passed since last draw (e.g. with QElapsedTimer) but don't try to schedule draws at regular intervals. You WILL fail ;) Graphics drivers and OS scheduler will make sure you do at least some of the time ;)

                                      Wings 1 Reply Last reply Reply Quote 1
                                      • Wings
                                        Wings @Chris Kawa last edited by

                                        @Chris-Kawa

                                        If you want high frequency display you should do your own painting...

                                        What's the point in doing high frequency drawing if the display's refresh rate is itself around 60Hz? You yourself said that let however fast my drawing might be, nothing can be drawn anything on screen faster than ~16.6ms.

                                        1 Reply Last reply Reply Quote 0
                                        • Chris Kawa
                                          Chris Kawa Moderators last edited by Chris Kawa

                                          By high frequency I meant those 60Hz. This as opposed to just setting a text in a UI widget, which is not reliable to achieve even that.
                                          The difference is that with your own drawing you can make sure you are ready every frame the display displays. Setting text in a UI widget is just telling it to update it but it will do so only when it is ready to do so, which is out of your control.

                                          1 Reply Last reply Reply Quote 0
                                          • KiwiJeff
                                            KiwiJeff @Wings last edited by

                                            @Wings said:

                                            @KiwiJeff said:

                                            Out of curiosity, but how are you actually measuring the time? It sounds like something I might want to check out myself.

                                            Right now I'm using a Qt::PreciseTimer type QTimer. But, probably I'll move to one with <10ms resolution.

                                            I was afraid I would get an answer like that. I mean, you are more or less guessing the speed inside the system, while your use case is to have a preserved speed. All you know in the end is the time between the "sure, put the text up" and the "sure, clear the text" and not the actual time on the screen? Of course, if this time is lower when using the QPainter/QML rather then setText, I would go for that.

                                            In the end, I think the only way to know if your software works for your use case is to have a high speed camera. And, as mentioned in other replies, a calibrated system.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post