PDA

View Full Version : Is there an event or signal after the UI has been set



pixaeiro
11th December 2014, 18:03
Hello,

I have QMainWindow with a QSplitter as the central widget, and the splitter has two QWidgets: top_widget and bottom_widget. I'd like to set the default size of bottom_widget to 100 on new, and allow this size to be saved and loaded. On Load I want to restore this value.

My question is: Where is the best place to set this default size to 100? Is there an event or signal the the QMainWindow receives after all children widgets have been positioned and resized?

Thank you!

wysota
11th December 2014, 18:34
There are many possibilities, e.g. using invokeMethod() with Qt::QueuedConnection. Or you can do that the first time the widget is shown (using showEvent()). Or possibly using other means.

d_stranz
12th December 2014, 20:08
In my apps I find it easiest to restore the window state in the showEvent() and to save it in the closeEvent(). You can also restore the state in the constructor if you wish, and it will be applied when the window is shown.

pixaeiro
16th December 2014, 01:04
Thank you! I'll try your suggestions. For the moment I am doing my stuff in the resize event only when the top and bottom widgets have size, and only once...

d_stranz
16th December 2014, 03:20
I am doing my stuff in the resize event

Better to do it in the show event. When this occurs, the widget (and its children) have been properly sized and positioned (by layouts), so you can safely examine their sizes and positions and resize or move them as you wish.

As you have probably seen, the resize event can be called multiple times, including when widgets have no sizes.