I am trying to create a painter inside of the paintEvent, inside of my subclass of QPlainTextEdit. When I try to create the painter and draw a single point I get warning/error messages and nothing happens.

def paintEvent(self, evt):
update_rect = evt.rect()
painter = QPainter(self)
painter.setPen(Qt.red)
painter.drawPoint(update_rect.x(), update_rect.y())


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

I don't understand why this message is occurring while it is clear that I am in a paint event. Is it not possible to use a painter inside of QPlainTextEdit?

By the way I am doing this with PyQt.

Thanks for any help,