PDA

View Full Version : Sizes in construction - different behaviour Qt5 to Qt4 (example attached)



sedi
24th April 2014, 11:59
Hi,

I've noticed a change in the way, sizes are set up in the construction process. With 4.7.0 I am able to get the final size of the app in MainWindow's constructor, with 5.2.1 this seems to have changed somehow.

I've created a minimal, compileable example that demonstrates the difference by qDebug()ing the size information at various steps while constructing the QMainWindow. (--> see Attachments, there's also a screenshot of the different outputs): 10307

Please note that both source codes are identical apart from the "<QtWidgets/"-stuff in the #include-Sections.
Both systems are set up in a Win7-environment, the 5.2.1 is running on a VM though. For now, I've tested this for Windows/MinGW.

- Is this a bug or a "feature"? Shall I file a former, if it is one?
- Is there a sensible workaround to obtain the final size already in the MainWindow constructor?

It's actually workaroundable by calling all the initialisation stuff from the nth resizeEvent (for me: n=3) instead of from the constructor, but that seems to be a bit hacky for me.
I am aware of this thread (http://www.qtcentre.org/threads/48760-Getting-size-of-a-QGraphicsScene) - so the conclusion is that the code shouldn't have worked in the first place, but just did?

I am actually quite curious about what kind of underlying architecture change caused this behavioural difference..

Sebastian

anda_skoa
24th April 2014, 13:10
It is generally not advisable to rely on size() when the widget has not been shown yet.

sizeHint() can come close provided no other effects influence the window's size (e.g. the windowing system resizing the window).

size() usually has a good initial value when retrieved from showEvent() though.

Cheers,
_