允许调整大小以使pyqt中的pixmap较小
我有一个Qlabel
显示QPIXMAP
,其水平和垂直策略设置为扩展。我已经编写了单独的代码,以根据小部件的大小自动缩放PixMap,但是无法调整窗口以使图像大小,并且导致它无法使其变小。如何自由调整窗口?
调整代码:
def resizeEvent(self, a0: QtGui.QResizeEvent):
self.page.setPixmap(
self.loader.img.scaled(
self.page.width(), self.page.height(), QtCore.Qt.KeepAspectRatio
)
)
I have a QLabel
showing a QPixmap
that has both horizontal and vertical policies set to expanding. I have written separate code to automatically scale the pixmap according to the size of the widget, but the window cannot be resized to make the image smaller than it is, and it results in it not being able to be made smaller. How do I allow the window to be resized freely?
Resizing code:
def resizeEvent(self, a0: QtGui.QResizeEvent):
self.page.setPixmap(
self.loader.img.scaled(
self.page.width(), self.page.height(), QtCore.Qt.KeepAspectRatio
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是从
qwidget
覆盖 paintEvent + code> qtransform 以缩放图像以适合。The easiest way is to inherit from
QWidget
overridepaintEvent
and useQTransform
to scale image to fit.