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. How to draw text in QQuickItem?
Forum Updated to NodeBB v4.3 + New Features

How to draw text in QQuickItem?

Scheduled Pinned Locked Moved QML and Qt Quick
24 Posts 14 Posters 17.4k Views 2 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.
  • L Offline
    L Offline
    literA2
    wrote on last edited by
    #21

    Hi, I'm having this problem also.

    I need to render a text on my custom geometry, I don't want to use QPainter because of the blurry text issue in iOS (using QQuickPaintedItem class).

    Please advise. TIA.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      seyed
      wrote on last edited by
      #22

      I need it too, because performance.
      I looked at Qt's source code (qquicktextnode.cpp) and I found following lines. Perhaps it helps someone...

      QSGGlyphNode *QQuickTextNode::addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color,
                                       QQuickText::TextStyle style, const QColor &styleColor,
                                       QSGNode *parentNode)
      {
          QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext();
          QRawFont font = glyphs.rawFont();
          bool preferNativeGlyphNode = m_useNativeRenderer;
          if (!preferNativeGlyphNode) {
              QRawFontPrivate *fontPriv = QRawFontPrivate::get(font);
              if (fontPriv->fontEngine->hasUnreliableGlyphOutline())
                  preferNativeGlyphNode = true;
              else
                  preferNativeGlyphNode = !QFontDatabase().isSmoothlyScalable(font.familyName(), font.styleName());
          }
      
          QSGGlyphNode *node = sg->sceneGraphContext()->createGlyphNode(sg, preferNativeGlyphNode);
      
          node->setOwnerElement(m_ownerElement);
          node->setGlyphs(position + QPointF(0, glyphs.rawFont().ascent()), glyphs);
          node->setStyle(style);
          node->setStyleColor(styleColor);
          node->setColor(color);
          node->update();
      
          /* We flag the geometry as static, but we never call markVertexDataDirty
             or markIndexDataDirty on them. This is because all text nodes are
             discarded when a change occurs. If we start appending/removing from
             existing geometry, then we also need to start marking the geometry as
             dirty.
           */
          node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
          node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
      
          if (parentNode == 0)
              parentNode = this;
          parentNode->appendChildNode(node);
      
          return node;
      }
      
      1 Reply Last reply
      1
      • D Offline
        D Offline
        devel
        wrote on last edited by
        #23

        I'm making a custom QQuickItem too. And it needs to accept a delegate that'll appear in the specific position.

        So, is it the right solution to expose a QRect property and do a QML wrapper that creates and positions that sub-item with a Loader?

        Or it's somehow possible to attach other items directly to one of QSGNode of a custom QQuickItem?

        1 Reply Last reply
        0
        • A Alexey

          Hi,
          I want to implement my custom QQuickItem subclass and I want it to draw some text. I found out that there is a QQuickTextNode class, but it seems to be private. So my question is: how can I do text drawing with QQuickItem?

          Thanks in advance!

          V Offline
          V Offline
          vladstelmahovsky
          wrote on last edited by
          #24

          @Alexey the only way is to use QQuickText and use private classes

          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