<p>Can I put the painter into the class variables? :</p>

<pre><code>protected:
QPainter *myPainter;

...

void MyWidget::paintEvent(QPaintEvent *event)
{
    myPainter = new QPainter(this);
</code></pre>

don't do that.  just put it on the stack so that when it is destroyed in the destructor it will perform the painting automatically.
```
```
void MyWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    // use painter
    ...
    // paint object automatically closes and paint on desctruction
}
```
```