title: QWidget paint even not being called even with non-zero width and height?
body: <p>I am trying to make a scroll area hold a widget which will serve as a drawing area for a drag-and-drop editor I am trying to build. However, I can't seem to get it to draw.</p>
  
  <p>Here is a picture: <a href="http://i.imgur.com/rTBjg.png" rel="nofollow">http://i.imgur.com/rTBjg.png</a></p>
  
  <p>On the right the black space is what is supposed to be my scrollarea</p>
  
  <p>Here is the constructor for my the window class (I am using Qt-Creator):</p>
  
  <pre><code>ModelWindow::ModelWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::ModelWindow)
  {
      ui-&gt;setupUi(this);
  
      editor = new ModelEditorWidget(this);
  
      ui-&gt;scrollArea-&gt;setWidget(editor);
  }
  </code></pre>
  
  <p>The model editor widget looks like so:</p>
  
  <pre><code>//header
  
  class ModelEditorWidget : public QWidget
  {
      Q_OBJECT
  public:
      explicit ModelEditorWidget(QWidget *parent = 0);
  
  signals:
  
  public slots:
  
  protected:
      virtual void paintEvent(QPaintEvent *e);
  
  };
  
  //.cpp file:
  
  ModelEditorWidget::ModelEditorWidget(QWidget *parent) :
      QWidget(parent)
  {
      this-&gt;setAcceptDrops(true);
  
      this-&gt;resize(1000, 1000);
  
      cout &lt;&lt; this-&gt;rect().x() &lt;&lt; " " &lt;&lt; this-&gt;rect().width() &lt;&lt; endl;
  
      this-&gt;update();
  }
  
  void ModelEditorWidget::paintEvent(QPaintEvent *e)
  {
      cout &lt;&lt; "painting";
  
      QWidget::paintEvent(e);
  
      QPainter painter(this);
  
      painter.setBrush(QBrush(Qt::green));
      painter.setPen(QPen(Qt::red));
      painter.drawRect(400, 400, 50, 50);
      painter.fillRect(e-&gt;rect(), Qt::SolidPattern);
  }
  </code></pre>
  
  <p>I would think that this would set the modeleditorwidget's size to be 1000x1000 and then draw a green or red rectangle on the widget. However, the lack of a "painting" message in the command line from the cout at the beginning of the paintEvent shows that it isn't being executed. I first suspected this is because there was 0 width and 0 height on the widget. However, the cout in the constructor tells me that the widget is positioned at x = 0 and width = 1000 and so I assume that since that matches my resize statement that the height is also 1000 as was specified.</p>
  
  <p><strong>EDIT:</strong> By calling <code>cout.flush()</code> I got the "painting" output. However, that only deepens the mystery since the paint event doesn't look like it is actually painting. I am now calling show on both the scroll area and the widget as well.</p>
  
  <p>Does anyone see what I could be doing wrong here? Perhaps I am not adding the ModelEditorWidget to the scrollarea properly?</p>
  
  <p>Btw, I am very new to Qt and this is my first major GUI project using it. Most of my other GUI stuff was done using .NET stuff in C#, but since I want this to be cross platform I decided to stay away from C#.NET and mono and use Qt.</p>