Вопрос

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!

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top