[SOLVED] Fixed size QDialog with platform-specific widget sizes
-
I want to make a QDialog that starts at it's minimum size and can't be resized.
Different platforms/desktop themes have different minimum sizes for widgets; different default font sizes, item borders, etc, so I can't just set an absolute fixed size in the designer.
How do I do this? How do I create a fixed size QDialog that looks good in any desktop environment?
-
Hi,
IIRC, you can use setSizePolicy with QSizePolicy::Maximum for that.
Hope it helps
-
[quote author="SGaist" date="1392627281"]IIRC, you can use setSizePolicy with QSizePolicy::Maximum for that.[/quote]
Thanks. I'm not sure I understand. Setting the size policy to Maximum (on either the dialog or the central widget) doesn't seem to affect the initial size and does not prevent the user from resizing the window. Can you clarify?
-
I have perhaps misunderstood your problem. Do you want to have a QDialog of a fixed size e.g. 300x300 and have it's content resized within that ? Or have the dialog getting an initial size when all widgets in it are created and then have it locked at that size ?
-
I want to have the dialog get an initial size when all widgets in it are created, then have it locked at that size.
I'm looking for the same behavior as e.g. a QMessageDialog, which gets an initial size based on the contents of its label and buttons (which vary based on content and on system metrics) but is a fixed size after creation.
-
Ok, then what you can do is:
@setFixedSize(sizeHint());@
This should give you a fixed size dialog containing all your widget with a sensible size
-
Perfect, that works great. Thanks!