first_row = QtGui.QHBoxLayout()
setings_search = QtGui.QVBoxLayout()
search_label = QtGui.QLabel()
search_pixmap = QtGui.QPixmap()
search_pixmap.load('search.png')
#search_pixmap.scaledToWidth(130)
#search_pixmap.scaledToHeight(130)
search_label.setPixmap(search_pixmap)
setings_search.addWidget(search_label)
first_row.addLayout(setings_search)
The image doesn’t resize when I use both scaled
and scaledToWidth/Heigth
methods.
my window
On the picture I’ve shown what I already have and what I want to have.
Of course I can change size via Photoshop but I wonder how to do it programatically.
2
Answers
Try defining
paintEvent
for yourQWidget
. However, I only know how to paint thepixmap
on an absolute position (posX
,poxY
), not sure about relative position (i.e., in aQVBoxLayout
).where
width
andheight
are dimensions of your scaledpixmap
.As ekhumoro says in a comment, just use one of the
scaled
methods in QPixmap.gives exactly the right size.