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

Florian Bruhin me at the-compiler.org
Tue Nov 26 13:00:43 GMT 2019


On Tue, Nov 26, 2019 at 01:47:40PM +0100, Maurizio Berti wrote:
> I noticed a strange behavior when drawing over an existing QPixmap of a
> QLabel.
> When scaledContents is false (the default), the image is updated correctly:
> [...]
> 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?

I can reproduce with Qt 5.14, but I don't think it necessarily is a Qt bug.

Looking at the code, turning on scaledContents resizes the underlying pixmap
once and then caches it:


What's your actual usecase? You could probably either modify/redisplay the
pixmap, or perhaps have a widget with a transparent background over the QLabel


me at the-compiler.org (Mail/XMPP) | https://www.qutebrowser.org 
       https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
       GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
             I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20191126/6a509c43/attachment.sig>

More information about the PyQt mailing list