In my GUI there is a embeded QLabel with “fixed” Size. At least Size is fixed, if user would like to zoom in/out.
So there are many very usefull attempts with QLabels resizing due to the Pixmap. But I would like to keep my QLabel-Size fixed all the time! First view of the pic should be scaled to the Labelsize:
myPixmap = QtGui.QPixmap(filepath)
myScaledPixmap = myPixmap.scaled(self.ui.LBL_bild.size(), Qt.KeepAspectRatio)
On “Mouse over Label” – Event AND “Mouse-Wheel-turned” – Event the Picture should resize, without stretching the Label. Here is my attempt:
if self.mouse_over_pic:
self.ui.LBL_bild.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
px = self.ui.LBL_bild.pixmap()
lbl_size = self.ui.LBL_bild.size()
if px:
if event.angleDelta().y() > 0:
faktor = 1.1
else:
faktor = 0.9
new_width = int(px.width() * faktor)
old_ratio = px.width()/px.height()
new_height = int(new_width/old_ratio)
scaledPix = px.scaled(new_width, new_height, transformMode=Qt.SmoothTransformation)
self.ui.LBL_bild.setPixmap(scaledPix)
I’m facing two issues:
-
the Picture is getting really clumpsy during zooming… I guessed the SmoothTransformationMode should prevent it? So how can I keep the quality (solution/density) of the picture?
-
The Label is resizing with the pixmap. I have no clue how to prevent that. Even though I fixed the horizontal and vertical SizePolicy to Fixed, the Size is changed. I also tried painting instead of seting again:
painter = QtGui.QPainter(self.ui.LBL_bild) point = QtCore.QPoint(0, 0) point.setX(int((lbl_size.width() - scaledPix.width())/2)) point.setY(int((lbl_size.height() - scaledPix.height()) / 2)) print(point.x(), " ", point.y()) painter.drawPixmap(point, scaledPix)
But with that I didn’t get any change to the picture.
I am really looking forward to your ideas.