I have been given a qt widget containing some elements and layouts. I am trying to add an empty layout to this main widget (My plan is to populate it with a widget in the future). I am expecting the main widget to resize automatically if the layout is empty. How can I do that? I tried to play on the size policies of the widget but I did not get much results so far .
In the end the idea is to get the main widget (which is not contained in a layout by the way) to resize automatically if it contains an empty layout in itself
I think, you can look for adjustSize method of QWidget
. When you add or remove any internal widget in layout, you can make something like this:
QTimer::singleShot(0, this, SLOT(slotAdjustSize()));
...
void YourWidget::slotAdjustSize()
{
adjustSize();
}
Size of your widget will be fit to its contents.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.