I'm having a problem where I cannot deterministically tell when a layout takes place.
Simplified example:
I have a widget with two sub-widgets.
- Top widget has expanding width and fixed height. Let's say the fixed height defaults to 50.
- Bottom widget has expanding height and width
- There's a vertical layout set up.
Let's say there's a button somewhere i can click to run code. The button is not on the widget itself to make things simple...
When the button is clicked, i do the following:
- I measure the height of the bottom expandable widget. The height is 100.
- I then "topWidget->SetMaximumHeight(100)", and "topWidget->SetMinimumHeight(100)"
- I measure the height of the bottom expandable widget again. The height is still 100
But I see the bottom expandable widget change height!
this means that when I do step #3, the layout hasn't taken place yet. No matter what I do, update(), updateGeometry() - I cannot get the bottom widget to change height between step #2 and step #3.
The only way for me to resolve this is to have a timer wait, say 250ms, and then measure the height of the bottom widget -- and then It's always correct - meaning the re-layout took place correctly
This is a crazy/dirty solution, but I don't have another. Is there an API I am missing to allow me to deterministically, synchronously change the layout and query for the new size of affected widgets right after?
QApplication::processEvents()
between steps #2 and #3 (it should do what the timer allow the event loop to do). – alexisdmactivate()
on your layout. – Pavel Strakhovresize event
coming from the top widget, and do step #3 after you have received the signal. According to the doc, " When resizeEvent() is called, the widget already has its new geometry." qt-project.org/doc/qt-5.0/qtwidgets/qwidget.html#resizeEvent – krb686