tags:

views:

339

answers:

2

I have a QDockWidget with a single square widget inside. I would like the ``QDockWidget to be resizable, but to always maintain a square shape, whereas by default it can be stretched disproportionately.

What combination of size policies, size hints, etc. do I need to set to do this?

+1  A: 

you have to override resizeEvent.

you have to compare width and height in this method,

if they are not equal, set them to equal numbers that you want related to the width or height.

ufukgun
I was hoping for an easier way than this. If I do this, I would have to figure out the user's intention (is the user trying to grow or shrink the width or the height or both?) or else I would override what the user is trying to do... Thanks anyways.
erjiang
maybe you can pick the bigger one on resize but this may cause problem on shrinking. (and vise verca on picking the smaller value on growing). so you should some how implement a mechanism.it would be the distance to the other corner of the widget when stretching with mouse.you should look at what applications do in normally and get inspired from them...
ufukgun
+1  A: 

When resizeEvent() is called, the widget already has it's new size. Calling resize() from it thus might result in flickering.

You can try reimplementing QWidget::heightForWidth(int); that might work as long as the QDockWindow is docked, and Qt's layout managers have control over it. But IIRC, at least on X11, heightForWidth() doesn't work on top-level widgets (windows).