Question

For example, I have a gridlayout which contains some QPixmaps. However, if the images in the QPixmaps are bigger than the cells of the gridlayout, they overflow and end up overlapping each other. How can I make them automatically scale down so that they fit in the layout? I have searched everywhere for this answer and cannot figure it out. Please help, thanks!

Was it helpful?

Solution

Use scaled() method from QPixmap class to to sacle down the pixmaps to a size that suits your situation. For example:

pix = QPixmap("path/to/image.png")
newPix = pix.scaled(w, h, Qt.KeepAspectRatio)

This snippet will scale the pix to wxh.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top