How can I programmatically make a dialog as small as possible?
-
Hi,
I have a dialog class drawn all from code - not using ui files. I want to resize it to the smallest dimensions that will still show the contained widgets. I have this in my constructor:
QVBoxLayout* layout = new QVBoxLayout; layout->addWidget(inputWidgetBox); layout->addWidget(buttonBox); setLayout(layout);
I thought adding this would accomplish my intentions:
layout->setSizeConstraint(QLayout::SetMinimumSize);
But it does not.
There must be a function somewhere to make the dialog as small as possible!! Which is it?
I can resize it with my mouse and see there is a minimum - that's what I want!Regards,
Juan -
@jdent said in How can I programmatically make a dialog as small as possible?:
layout->setSizeConstraint(QLayout::SetMinimumSize);
If this were to work at all it would actually need to be
SetMaximumSize
!But I think doing it on a layout won't achieve anything. I think you need to do it on the widget, i.e. the
QDialog
.I'll be honest and say that after years I still don't get layouts & sizes & size policies! :( If you do something like
dialog->resize(1, 1)
ordialog->resize(minimumSize())
does that work? -
@Ronel_qtmaster Not exactly what I am looking for. I want the dialog to be as small as possible. Can I query the widgets to find their size? and perhaps add the sizes to obtain the minimum size?
how can I iterate over all the children of a QWidget? maybe this could help... -