[PyQt] How do I get a clean empty transparent image?

David Boddie david at boddie.org.uk
Sun Jan 18 23:18:14 GMT 2009


On Sun Jan 18 23:06:59 GMT 2009, Grzegorz Adam Hankiewicz wrote:

> I have the following lines of code:
>
>          big = QImage(size, images[0].height(), QImage.Format_ARGB32)
>          big.save("test.png")
>
> The resulting test.png file contains random garbage, so I need to
> clean that out. I've tried to use a QPainter calling eraseRect(), but
> that removes the transparency by drawing a color. If I try setting the
> brush transparent, nothing is drawn, and nothing is cleared.

Yes, this is a common problem.

> How can I clean the image leaving the image transparent?

Use the QImage.fill() method, passing a transparent colour:

  big = QImage(size, images[0].height(), QImage.Format_ARGB32)
  big.fill(qRgba(0,0,0,0))

David


More information about the PyQt mailing list