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

Jim Bublitz jbublitz at nwinternet.com
Wed Aug 22 23:43:43 BST 2007


On Wednesday 22 August 2007 13:49, Devon wrote:
> Hi, folks -
>
> Here is a dummy version of a derived tree widget:
>
> ----------------------------
> class MyTreeWidget(QTreeWidget):
>     def __init__(self, parent=None):
>         QTreeWidget.__init__(self, parent)
>
>     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?
>
> I'm using Qt 4.3.1, PyQt 4.3 and SIP 4.7

The first thing to look at is whether e is a paint event or not:

if e.type () == QEvent.Paint:
	print "Paint Event"
else:
	print "not Paint Event", e.type ()

The values for e.type () are on the QEvent page in the Qt docs.

Jim


More information about the PyQt mailing list