title: Qt Quick - How to use a c++ class inheriting from QQuickPaintedItem in a qml interface?
body: <p>I'm newbie with Qt 5.13.0. In a Visual Studio 2019 project, I need to display a custom painted item inherited from the QQuickPaintedItem class in a qml interface. The custom item is written in a c++ class named WQTMessageItem, which is declared as follow:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class WQTMessageItem : public QQuickPaintedItem
  {
      Q_OBJECT
      Q_PROPERTY(bool rightAligned READ isRightAligned WRITE setRightAligned NOTIFY rightAlignedChanged)
  
      signals:
          void rightAlignedChanged();
  
      public:
          WQTMessageItem(QQuickItem* parent = 0);
  
          void paint(QPainter* painter);
  
          bool isRightAligned();
          void setRightAligned(bool rightAligned);
  
      private:
          bool m_RightAligned;
  };
  </code></pre>
  
  <p>On the c++ side, I'm trying to declare the above class to the qml engine this way:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>QQmlContext* pContext = engine.rootContext();
  std::unique_ptr&lt;WQTMessageItem&gt; pMessageItem(new WQTMessageItem());
  pContext-&gt;setContextProperty("WQTMessageItem", pMessageItem.get());
  pMessageItem.release();
  </code></pre>
  
  <p>And finally, I'm trying to use the above custom item in a ListView declared in a qml file, this way:</p>
  
  <pre class="lang-css prettyprint-override"><code>ListView
  {
      anchors.bottom: controls.top
      anchors.bottomMargin: 2
      anchors.top: parent.top
      id: balloonView
  
      delegate: WQTMessageItem
      {
          anchors.right: index % 2 == 0 ? undefined : parent.right
          height: 60
          rightAligned: index % 2 == 0 ? false : true
          width: balloonWidth
      }
  
      model: balloonModel
      spacing: 5
      width: parent.width
  }
  </code></pre>
  
  <p>Unfortunately this doesn't work. My application compiles and links, but closes immediately on running, with the following error message:</p>
  
  <pre><code>QQmlApplicationEngine failed to load component
  qrc:/main.qml:33 WQTMessageItem is not a type
  </code></pre>
  
  <p>I tried to find a solution by myself, without success. Can someone explain me how I should modify my above code to allow it to work?</p>