[PyQt] QLabel with scaled contents pixmap not updated after painting

Maurizio Berti maurizio.berti at gmail.com
Tue Nov 26 12:47:40 GMT 2019

I noticed a strange behavior when drawing over an existing QPixmap of a
When scaledContents is false (the default), the image is updated correctly:

class Test(QtWidgets.QLabel):
    def __init__(self):
        self.setPixmap(QtGui.QPixmap(400, 400))

    def mousePressEvent(self, event):
        qp = QtGui.QPainter(self.pixmap())
        qp.drawRect(100, 100, 200, 200)

But if I use setScaledContents(True) in the init, the image is not updated
anymore, not even after calling repaint or hiding/showing the label again.
So far, the only way I found to show the changes is to set the scaled
contents to false and back again to true, right after closing the painter.

I have to specify that I'm using an old version of PyQt (5.7.1) which I
cannot update, so maybe the issue has been already solved. Also, I'm on
Linux, using xorg-x11.

Can anyone confirm this?


È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20191126/eec57733/attachment.html>

More information about the PyQt mailing list