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. drawText in QQuickItem

drawText in QQuickItem

Scheduled Pinned Locked Moved QML and Qt Quick
qquickitemtext
11 Posts 3 Posters 4.6k 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.
  • T Offline
    T Offline
    themts
    wrote on last edited by
    #1

    Hey guys,

    I'm writing a QQuickItem to display a ruler.
    So I have several lines and some text.
    I have no problem to draw the lines but I don't see a good way to draw my text next to it.

    As it seems that there is no textGeometry I would like to instantiate qml-Textelements from c++.
    In what class do I find the qml-textelements?

    CU
    mts

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi

      AFAIK it won't be easy to display text in QQuickItem instead did you consider using QQuickPaintedItem ? It uses QPainter with which you can use one of the drawText functions to draw text.

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        themts
        wrote on last edited by
        #3

        QQuickPaintedItem will use a texture to display my text.
        Lets say I rescale the ruler with an animation. On every render I will have to create a new texture and I think the performance will be quite bad.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Yes it does but you wont need to do it manually as the paint() will do it internally. I don't know how GPU intensive your application is but I had been using it for some of my projects which included animations and it worked fine without any noticeable performance drop.

          157

          1 Reply Last reply
          0
          • T Offline
            T Offline
            themts
            wrote on last edited by
            #5

            Ok, so I tried to use QQuickPaintedItem now.
            My idea was to mix painting with paint() and direct drawing with updatePaintNode().
            Unfortunately paint gets never called when I implement the updatePaintNode() function.
            Is there a workaround?

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              If using QQuickPaintedItem it's better to use paint() rather than updatePaintNode().
              AFAIK there's no way to use QPainter in updatePaintNode().

              157

              L 1 Reply Last reply
              0
              • p3c0P p3c0

                If using QQuickPaintedItem it's better to use paint() rather than updatePaintNode().
                AFAIK there's no way to use QPainter in updatePaintNode().

                L Offline
                L Offline
                literA2
                wrote on last edited by
                #7

                @p3c0 i tried using QQuickPaintedItem and use QPainter to draw text, however seems like there's a problem when rendering the text, it appears to be pixelated or blurred in iOS (retina deisplay) devices while on Android, everything is perfect. Read somewhere that antialiasing isn't working on QQuickPaintedItem. Do you know any workaround on this? TIA.

                p3c0P 1 Reply Last reply
                0
                • L literA2

                  @p3c0 i tried using QQuickPaintedItem and use QPainter to draw text, however seems like there's a problem when rendering the text, it appears to be pixelated or blurred in iOS (retina deisplay) devices while on Android, everything is perfect. Read somewhere that antialiasing isn't working on QQuickPaintedItem. Do you know any workaround on this? TIA.

                  p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  @literA2 Seems like a bug. Check QTBUG-40489. It still unresolved. But there is a patch provided.

                  157

                  L 1 Reply Last reply
                  0
                  • p3c0P p3c0

                    @literA2 Seems like a bug. Check QTBUG-40489. It still unresolved. But there is a patch provided.

                    L Offline
                    L Offline
                    literA2
                    wrote on last edited by
                    #9

                    @p3c0 Thank you for the quick reply.

                    I actually encountered such bug report already however I can't find the qsgpainternode.cpp file in my Qt folder. Did i miss some patch or update to download? TIA.

                    p3c0P 1 Reply Last reply
                    0
                    • L literA2

                      @p3c0 Thank you for the quick reply.

                      I actually encountered such bug report already however I can't find the qsgpainternode.cpp file in my Qt folder. Did i miss some patch or update to download? TIA.

                      p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #10

                      @literA2 Seems it has been moved to a other class. May be new changes should be added here. Better to ask there for a more details.

                      157

                      L 1 Reply Last reply
                      0
                      • p3c0P p3c0

                        @literA2 Seems it has been moved to a other class. May be new changes should be added here. Better to ask there for a more details.

                        L Offline
                        L Offline
                        literA2
                        wrote on last edited by
                        #11

                        Thanks @p3c0

                        Based on the documentation, QtDeclarative has already been deprecated in favor of the two new classes: Qt Quick and Qt QML. QQuickPaintedItem can be use as convenient way to port QDeclarativeItem-based classes that use the QPainter API.

                        I've been searching on the internet how to render text on QSG nodes but to no avail. I'm still stuck into this 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