Sunday 4 March 2012

Fixed Size Dialog in QT Desinger 4

I've been trying, on and off for the last day or so, to create fixed size dialogs in QT Designer. By that I mean dialogs that are not resizeable by the the end-user. It should be simple I thought (it is), but it's not obvious to somebody who just jumps in to the designer and starts playing. Googling left me confused, with a number of different solutions offered (manually setting min/max sizes; calculating 'stuff' at the start of the app...) but not the QTD solution I was looking for. This blog post will serve mainly as a reminder to myself, but maybe it'll be a help to others too.

This thread (qtforum.org) was the closest I came but that didn't tell the entire story for a QTD newbie:
The actual answer is to apply a layout to your dialog and set the resizeMode property to 'fixed'. This will handle any issues with fonts, i18n, etc.

Most people miss this (see above).
With the final post inluding:
@Chickenblood
Yes, you're right it works that way. Thanks for pointing that out again and again and again. I missed that ;)

As you said, In QT3 designer, after you used Layout in a grid, you can find the resizeMode property and set it fixed there.
(2 other layout properties appear also in the dialog properties : LayoutSpacing and LayoutMargin)

In QT4 it is not available in the property editor when we make a Layout in a grid.(QT4.0.0)
So we need code to do it.
Well that post is from 2005 and the property is there now in Qt4. Great! :) Also I already had some layouts in my dialog (and a great feature they are too), so I just set the layoutSizeConstraint in one of those? No. Okay, all of them then? No. Create a single parent form layout chuck everything inside it and set it's size constraint? No.

Meh!

Finally, the penny reaches escape velocity. You need to have the window selected;

Easy when you know how. Maybe I should just go read the documentation for once...but where is the fun in that ;o)

No comments: