title: QtQuick using QQuickTextNode
body: <p>I tried to use QQuickTextNode in a custom <code>QQuickitem</code> but ended up not seeing anything on the screen (I know it is a private API)... </p>
  
  <p>Could anyone tell me what I am doing wrong?</p>
  
  <p>Header:</p>
  
  <pre><code>#pragma once
  
  #include &lt;QQuickItem&gt;
  #include &lt;QTextLayout&gt;
  
  class TextItem: public QQuickItem {
  
      Q_OBJECT
  
      Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
  
  public:
  
      TextItem(QQuickItem *parent = nullptr);
      ~TextItem();
  
      QString text() const;
  
  public slots:
  
      void setText(QString text);
  
  signals:
  
      void textChanged(QString text);
  
  protected:
  
      QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) override;
  
  private:
  
      QString         _text;
      QTextLayout    *_layout;
  };
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>#include "text_item.h"
  
  #include &lt;QTextLayout&gt;
  
  #include &lt;private/qquicktextnode_p.h&gt;
  
  TextItem::TextItem(QQuickItem *parent)
      : QQuickItem(parent)
      , _layout(new QTextLayout)
  {
      setFlag(ItemHasContents, true);
  }
  
  TextItem::~TextItem()
  {
      delete _layout;
  }
  
  QString TextItem::text() const
  {
      return _text;
  }
  
  void TextItem::setText(QString text)
  {
      if (_text == text)
          return;
  
      _text = text;
      emit textChanged(_text);
  }
  QSGNode *TextItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data)
  {
      QQuickTextNode *node = nullptr;
      if (!oldNode) {
          node = new QQuickTextNode(this);
      } else {
          node = static_cast&lt;QQuickTextNode *&gt;(oldNode);
      }
      _layout-&gt;setText(_text);
      QQuickText::TextStyle textStyle;
      node-&gt;addTextLayout(QPointF(5, 5), _layout);
      return node;
  }
  </code></pre>