title: Creating custom widget to be promoted in Qt designer
body: <p>I am developing a GUI application in Qt, and I have some difficulties embedding a custom widget in my ui. From Qt's <a href="http://doc.qt.nokia.com/4.7-snapshot/designer-using-custom-widgets.html#promoting-widgets" rel="noreferrer">documentation</a> I can see it is possible to promote such a widget. However, I am still a little confused about how this should be done.</p>
  
  <p>My widget QTreeWidget is heavily inspired by Qt's <a href="http://doc.qt.nokia.com/latest/network-torrent.html" rel="noreferrer">torrent example</a>, where I want to embed this in my application:</p>
  
  <p>So I have for my <strong>FilesView</strong> class (not included the src code, because it is trivial):</p>
  
  <pre><code>#include &lt;QTreeWidget&gt;
  #include &lt;QUrl&gt;
  #include &lt;QFile&gt;
  #include &lt;QDragMoveEvent&gt;
  #include &lt;QDropEvent&gt;
  
  // FilesView extends QTreeWidget to allow drag and drop.
  class FilesView : public QTreeWidget
  {
      Q_OBJECT
  public:
      FilesView(QWidget *parent = 0);
  
  signals:
      void fileDropped(const QString &amp;fileName);
  
  protected:
      void dragMoveEvent(QDragMoveEvent *event);
      void dropEvent(QDropEvent *event);
  };
  </code></pre>
  
  <p>To this is a <strong>TorrentViewDelegate</strong> class (comment the progressbar for testing purposes)</p>
  
  <pre><code>#include &lt;QItemDelegate&gt;
  #include &lt;QMainWindow&gt;
  #include &lt;QApplication&gt;
  
  // TorrentViewDelegate is used to draw the progress bars.
  class TorrentViewDelegate : public QItemDelegate
  {
      Q_OBJECT
  public:
      inline TorrentViewDelegate(QMainWindow *mainWindow) : QItemDelegate(mainWindow) {}
  
      inline void paint(QPainter *painter, const QStyleOptionViewItem &amp;option,
                        const QModelIndex &amp;index ) const
      {
          if (index.column() != 2) {
              QItemDelegate::paint(painter, option, index);
              return;
          }
  
          // Set up a QStyleOptionProgressBar to precisely mimic the
          // environment of a progress bar.
          QStyleOptionProgressBar progressBarOption;
          progressBarOption.state = QStyle::State_Enabled;
          progressBarOption.direction = QApplication::layoutDirection();
          progressBarOption.rect = option.rect;
          progressBarOption.fontMetrics = QApplication::fontMetrics();
          progressBarOption.minimum = 0;
          progressBarOption.maximum = 100;
          progressBarOption.textAlignment = Qt::AlignCenter;
          progressBarOption.textVisible = true;
  
          // Set the progress and text values of the style option.
          //int progress = qobject_cast&lt;MainWindow *&gt;(parent())-&gt;clientForRow(index.row())-&gt;progress();
          int progress = 40;
          progressBarOption.progress = progress &lt; 0 ? 0 : progress;
          progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
  
          // Draw the progress bar onto the view.
          QApplication::style()-&gt;drawControl(QStyle::CE_ProgressBar, &amp;progressBarOption, painter);
      }
  };
  </code></pre>
  
  <p>In the example the embed the widget in MainWindow as:</p>
  
  <pre><code>filesView = new FilesView(this);
  filesView-&gt;setItemDelegate(new TorrentViewDelegate(this));
  filesView-&gt;setHeaderLabels(headers);
  filesView-&gt;setSelectionBehavior(QAbstractItemView::SelectRows);
  filesView-&gt;setAlternatingRowColors(true);
  filesView-&gt;setRootIsDecorated(false);
  ui-&gt;verticalLayout_Filebox-&gt;addWidget(filesView);
  </code></pre>
  
  <p>How can I do this from the Qt designer? </p>