Try to search your question here, if you can't find : Ask Any Question Now ?

Resizing a QWindow to fit contents

HomeCategory: stackoverflowResizing a QWindow to fit contents
Avatarjohn asked 1 week ago

The main window of my PyQt5 application is set up with a text label along the top above a custom canvas widget which displays an image:

self.canvas = Canvas()  # a custom QtWidgets.QWidget subclass

self.label = QtWidgets.QLabel()

layout = QtWidgets.QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)

content = QtWidgets.QWidget()

This looks like this, which is what I want:

enter image description here

When the canvas changes to display a smaller image, I want to shrink the window to fit accordingly. I tried this when the image changes:

self.canvas.setFixedSize(image.width(), image.height())

enter image description here

It seems that the minimum size that I can give the window if I manually drag to resize it is the size that fits the contents, but why isn’t it resizing to this automatically?

1 Answers
Best Answer
AvatarAmit answered 1 week ago
Your Answer

1 + 14 =

Popular Tags

WP Facebook Auto Publish Powered By :