Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GUI and performance
QtWS25 Last Chance

GUI and performance

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.4k Views
  • 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.
  • R Offline
    R Offline
    Rhadel
    wrote on last edited by
    #1

    Hi,

    As I explained in other posts, I'm trying to build an application that should be able to show a very long strings, just as shown at the image below.
    !http://i43.tinypic.com/2945vmc.png(Image)!

    I've already tried with some techniques in order to solve this problem: labels for any row, just writing in a scene as a graphicScene item / object, into a table, into a Simple text area...

    But I get always the same low performance. Maybe I should I use openGL with an orthogonal projection (I just need 2D, it's just text) or something like that. There would be some trick to solve it, because I've seen some old applications that are able to load and show this kind of data, why not Qt?

    Some help here?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      ScottR
      wrote on last edited by
      #2

      Derive a class from QTextEdit and override scrollContentsBy?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rhadel
        wrote on last edited by
        #3

        Thank you ScottR for your fast reply.

        What should I do in scrollContetsBy?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          ScottR
          wrote on last edited by
          #4

          I don' t know, I'm just starting out in Qt.

          However, in straight win32 programming this would be a case for an owner-draw control. There must be some equivalent in Qt.

          Obviously the scrolling in a normal QTextEdit isn't designed for strings that are tens of thousands of characters long. You should reimplement it in a way that gives you the performance you need.

          Maybe you could keep the string in memory and only put into the edit control a small portion of it. Then when the user attempts to scroll past this small amount, replace it with the "next" portion.

          Note that I don't know if this is possible in Qt; it's the way I would do it in native win32. I don't even know if you're working in Windows...

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            In the example shown, you are always drawing the same text. I assume in your real data, you have different texts.

            The fastest way (without graphics hardware support) to paint texts that I know is to:

            • Create a custom QGraphicsItem that does the text drawing in the paint event
            • Set the caching mode to DeviceCoordinateCaching.

            However, in your case there would still be a lot of overhead, for only a part of the text you have is actually visible.

            Therefore, you could further optimize by using the exposedRect in QStyleOptionGraphicsItem (to get this, you need to set the QGraphicsItem::ItemUsesExtendedStyleOption flag).
            In this case, I would turn the DeviceCoordinateCaching of, and do my own caching by drawing first to a pixmap, then painting the pixmap in the paint event. Whenever a different part of the text becomes visible, you would only need to add the part that became newly exposed to the pixmap (with a overlap of some pixels to avoid jittery edges).

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NicuPopescu
              wrote on last edited by
              #6

              you could take a look at "Wheel Scroller Example":http://qt-project.org/doc/qt-5.0/qtwebkitexamples/webkitwidgets-scroller-wheel.html

              I cannot remember how big is your strings but I modified the example to show 1 mil. strings (* ~ 6 chars each) for each wheel and it still runs fast

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rhadel
                wrote on last edited by
                #7

                Hello there,

                Thank you for your replies.

                I'm trying your 2 ways: by setting DeviceCoordinateCaching is still too low. So, I'm trying to draw the text in a pixmap, but if I try to do it using a QPainter new object it's not active. I cannot use the active painter passed as argument in paint method, because is the main painter. Any other way to write text inside a pixmap?

                With your solution, if I've correctly understood, I should reimplement the scroll bar. I'm not sure if it can be applied in this case.

                Many thanks

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Asperamanca
                  wrote on last edited by
                  #8

                  The method to paint into a pixmap is to create a new painter.
                  Then you have to call beginPaint() and pass the pointer to the pixmap as an argument. After you are finished, you call endPaint().

                  The painter will only add to the pixmap. That means, if you hold the pixmap as a member, you can add those parts of text that just became visible, then just call drawPixmap on the painter you received with the paint() method.

                  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