I'm creating a new widget, by subclassing the QWidget class. I'd like to be able to set a ratio (for its height and its width) for this widget, which will always be maintained.
For this, I've always searched, using the Qt5 documentation, Google, and Stackoverflow. Obviously, I've found answers: in particular, this one. But, unfortunately, not even one is fully effective:
- Setting the
sizeIncrement
does totally nothing, even if the widget is a window - I tried to overload resizeEvent, but I really don't know how to do this...
If I follow this answer, two things:
- If the widget is a top-level window, the ratio isn't maintained at all, I can resize it as I want.
- If I place this widget in a layout, if I just increase both width and height of the window, the ratio is maintained. But as soon as I increase the width or the height to much, the widget is flattened. Instead, I would like that the layout automatically adjust its size to keep the widget's ratio.
So, how could I manage to keep the aspect ratio of a subclassed QWidget?