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

Devon devon.rueckner at temboo.com
Thu Aug 23 16:04:19 BST 2007

> 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.

I'm not explicitly calling begin() - I believe that's happening in
QPainter(self).  painter.end() is not the root cause.

this script produces the issue if anyone wants to try it:

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class MyTreeWidget(QTreeWidget):
    def __init__(self, parent=None):
        QTreeWidget.__init__(self, parent)
    def paintEvent(self, e):
        QTreeWidget.paintEvent(self, e)
        painter = QPainter(self)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    tree = MyTreeWidget()

QPainter::begin: Widget painting can only begin as a result of a paintEvent

More information about the PyQt mailing list