[PyQt] can't create a QPainter in QTreeWidget's paintEvent

David Boddie david at boddie.org.uk
Thu Aug 23 15:28:57 BST 2007


On Wed Aug 22 21:49:05 BST 2007, Devon wrote:

> Here is a dummy version of a derived tree widget:

[...]

>     def paintEvent(self, e):
>         QTreeWidget.paintEvent(self, e)
>         painter = QPainter(self)
>         painter.end()

[...]

> When an instance is added to a layout, I get the following:
> 
> ----------------------------
> QPainter::begin: Widget painting can only begin as a result of a paintEvent
> QPainter::end: Painter not active, aborted
> ----------------------------
> 
> Any ideas what is causing the the painter to think it's not actually
> in a paintEvent?

If you pass a device (self in this case) when you create a QPainter, don't
call its begin() or end() methods. I think its the end() call that actually
triggers this message in this case.

David


More information about the PyQt mailing list