[PyQt] Use QPainter as QMutexLocker in a with-statement?

Phil Thompson phil at riverbankcomputing.com
Thu Jan 5 16:23:38 GMT 2012


On Thu, 05 Jan 2012 15:28:13 +0100, Gerard Vermeulen <gav451 at gmail.com>
wrote:
> Hi,
> 
> I would like to use QPainter as QMutexLocker in a with-statement, but:
> 
>  >>> pixmap = Qt.QPixmap(200, 200)
>  >>> with Qt.QPainter(pixmap) as painter:
> ...  painter.drawLine(0, 0, 200, 200)
> ...
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> AttributeError: __exit__
>  >>>

You would have to sub-class QPainter (in Python) and implement the
necessary context manager hooks.

Phil


More information about the PyQt mailing list