title: QT Quick Designer Custom Components are Blank?
body: <p>I'm doing some testing of QT Quick to see if i can use it as a GUI replacement for the old Ui files. I noticed in some of the examples that custom components will populate the library view. I managed to do that (apparently they must be in a sub dir of the qml file that uses them?). However these components do not render in the Qt Quick design window. There is actually nothing to grab or manipulate. Upon running the program, they render correctly.</p>
  
  <p>Does anyone have a solution? My source is below</p>
  
  <pre><code>import QtQuick 1.0
  import Chips 1.0
  
  Item {
      width: 100
      height: 62
      Chip
      {
  
      }
  }
  </code></pre>
  
  <p>chip.cpp</p>
  
  <pre><code>#include "Chip.h"
  
  #include &lt;QtGui&gt;
  
  
  Chip::Chip(QDeclarativeItem *parent)
      : QDeclarativeItem(parent)
  {
      x = 0;
      y = 0;
      color = QColor(0, 200, 0);
      setFlags(ItemIsSelectable | ItemIsMovable);
      setFlag(QGraphicsItem::ItemHasNoContents, false);
      setAcceptsHoverEvents(true);
  }
  
  
  //Chip::Chip(const QColor &amp;color, int x, int y, QDeclarativeItem *parent)
  //    : QDeclarativeItem(parent)
  //{
  //    this-&gt;x = x;
  //    this-&gt;y = y;
  //    this-&gt;color = color;
  //    setZValue((x + y) % 2);
  
  //    setFlags(ItemIsSelectable | ItemIsMovable);
  //    setFlag(QGraphicsItem::ItemHasNoContents, false);
  // setAcceptsHoverEvents(true);
  //}
  
  QRectF Chip::boundingRect() const
  {
      return QRectF(0, 0, 110, 70);
  }
  
  QPainterPath Chip::shape() const
  {
      QPainterPath path;
      path.addRect(14, 14, 82, 42);
      return path;
  }
  
  void Chip::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  {
      Q_UNUSED(widget);
  
      QColor fillColor = (option-&gt;state &amp; QStyle::State_Selected) ? color.dark(150) : color;
      if (option-&gt;state &amp; QStyle::State_MouseOver)
          fillColor = fillColor.light(125);
  
      const qreal lod = option-&gt;levelOfDetailFromTransform(painter-&gt;worldTransform());
      if (lod &lt; 0.2) {
          if (lod &lt; 0.125) {
              painter-&gt;fillRect(QRectF(0, 0, 110, 70), fillColor);
              return;
          }
  
          QBrush b = painter-&gt;brush();
          painter-&gt;setBrush(fillColor);
          painter-&gt;drawRect(13, 13, 97, 57);
          painter-&gt;setBrush(b);
          return;
      }
  
      QPen oldPen = painter-&gt;pen();
      QPen pen = oldPen;
      int width = 0;
      if (option-&gt;state &amp; QStyle::State_Selected)
          width += 2;
  
      pen.setWidth(width);
      QBrush b = painter-&gt;brush();
      painter-&gt;setBrush(QBrush(fillColor.dark(option-&gt;state &amp; QStyle::State_Sunken ? 120 : 100)));
  
      painter-&gt;drawRect(QRect(14, 14, 79, 39));
      painter-&gt;setBrush(b);
  
      if (lod &gt;= 1) {
          painter-&gt;setPen(QPen(Qt::gray, 1));
          painter-&gt;drawLine(15, 54, 94, 54);
          painter-&gt;drawLine(94, 53, 94, 15);
          painter-&gt;setPen(QPen(Qt::black, 0));
      }
  
      // Draw text
      if (lod &gt;= 2) {
          QFont font("Times", 10);
          font.setStyleStrategy(QFont::ForceOutline);
          painter-&gt;setFont(font);
          painter-&gt;save();
          painter-&gt;scale(0.1, 0.1);
          painter-&gt;drawText(170, 180, QString("Model: VSC-2000 (Very Small Chip) at %1x%2").arg(x).arg(y));
          painter-&gt;drawText(170, 200, QString("Serial number: DLWR-WEER-123L-ZZ33-SDSJ"));
          painter-&gt;drawText(170, 220, QString("Manufacturer: Chip Manufacturer"));
          painter-&gt;restore();
      }
  
      // Draw lines
      QVarLengthArray&lt;QLineF, 36&gt; lines;
      if (lod &gt;= 0.5) {
          for (int i = 0; i &lt;= 10; i += (lod &gt; 0.5 ? 1 : 2)) {
              lines.append(QLineF(18 + 7 * i, 13, 18 + 7 * i, 5));
              lines.append(QLineF(18 + 7 * i, 54, 18 + 7 * i, 62));
          }
          for (int i = 0; i &lt;= 6; i += (lod &gt; 0.5 ? 1 : 2)) {
              lines.append(QLineF(5, 18 + i * 5, 13, 18 + i * 5));
              lines.append(QLineF(94, 18 + i * 5, 102, 18 + i * 5));
          }
      }
      if (lod &gt;= 0.4) {
          const QLineF lineData[] = {
              QLineF(25, 35, 35, 35),
              QLineF(35, 30, 35, 40),
              QLineF(35, 30, 45, 35),
              QLineF(35, 40, 45, 35),
              QLineF(45, 30, 45, 40),
              QLineF(45, 35, 55, 35)
          };
          lines.append(lineData, 6);
      }
      painter-&gt;drawLines(lines.data(), lines.size());
  
      // Draw red ink
      if (stuff.size() &gt; 1) {
          QPen p = painter-&gt;pen();
          painter-&gt;setPen(QPen(Qt::red, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
          painter-&gt;setBrush(Qt::NoBrush);
          QPainterPath path;
          path.moveTo(stuff.first());
          for (int i = 1; i &lt; stuff.size(); ++i)
              path.lineTo(stuff.at(i));
          painter-&gt;drawPath(path);
          painter-&gt;setPen(p);
      }
  }
  
  void Chip::mousePressEvent(QGraphicsSceneMouseEvent *event)
  {
      QGraphicsItem::mousePressEvent(event);
      update();
  }
  
  void Chip::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
  {
      if (event-&gt;modifiers() &amp; Qt::ShiftModifier) {
          stuff &lt;&lt; event-&gt;pos();
          update();
          return;
      }
      QGraphicsItem::mouseMoveEvent(event);
  }
  
  void Chip::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
  {
      QGraphicsItem::mouseReleaseEvent(event);
      update();
  }
  
  QColor Chip::getColor() const
  {
      return color;
  }
  
  int Chip::getX() const
  {
      return x;
  }
  
  int Chip::getY() const
  {
      return y;
  }
  
  void Chip::setColor(const QColor &amp;color)
  {
      this-&gt;color = color;
  }
  
  void Chip::setX(const int &amp;x)
  {
      this-&gt;x = x;
  }
  
  void Chip::setY(const int &amp;y)
  {
      this-&gt;y = y;
  }
  </code></pre>
  
  <p>chip.h</p>
  
  <pre><code>#ifndef CHIP_H
  #define CHIP_H
  
  #include &lt;QtGui/QColor&gt;
  #include &lt;QDeclarativeItem&gt;
  
  class Chip : public QDeclarativeItem
  {
      Q_OBJECT
      Q_PROPERTY(int x READ getX WRITE setX)
      Q_PROPERTY(int y READ getY WRITE setY)
      Q_PROPERTY(QColor color READ getColor WRITE setColor)
  
  public:
      Chip(QDeclarativeItem *parent = 0);
      Chip(const QColor &amp;color, int x, int y);
  
      QRectF boundingRect() const;
  
      QColor getColor() const;
      int getX() const;
      int getY() const;
  
      void setColor(const QColor &amp;color);
      void setX(const int &amp;x);
      void setY(const int &amp;y);
  
      QPainterPath shape() const;
      void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget);
  
  protected:
      void mousePressEvent(QGraphicsSceneMouseEvent *event);
      void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
      void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
  
  private:
      int x, y;
      QColor color;
      QList&lt;QPointF&gt; stuff;
  };
  
  #endif
  </code></pre>
  
  <p>In my investigation of this issue, i learned that you can add custom widgets to the QT Designer. I might have to check that out as well before I make my decision. Any help will be appreciated, thanks.</p>