Domanda

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!

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top