Turtle10000
Turtle10000

Reputation: 252

How to draw Qt widgets in a QTabWidget in non-selected tabs?

My QTabWidget has 2 tabs on launch.

The problem is that currently the size of the elements is 640x480 (apparently the default value), if tab 2 was not shown yet. Once tab 2 is selected, the elements are "drawn" and get their sizes depending on resolutio, window size etc.
How can I force the drawing of the elements in the background without opening tab 2, so that I can obtain the sizes the elements would have if the tab was opened? repaint and update do not do that.

My current workaround is to launch with tab 2 open and switch to tab 1 in main.cpp between myWindow.show() and myApp.exec() but that seems a bit dirty.

Upvotes: 2

Views: 199

Answers (2)

Jeremy Friesner
Jeremy Friesner

Reputation: 73041

For performance reasons, a QWidget's size() method is not guaranteed to return its expected value until after the QWidget has actually been laid out and shown.

If you need to know in advance what a QWidget's size would be, you can call its sizeHint() method instead, and that will force the calculation to be performed right away, so that the correct size can be returned even if it hasn't already been computed.

Upvotes: 2

SajadBlog
SajadBlog

Reputation: 575

according to Document resizeEvent was never called when the widget is not visible and also paintEvent. this is a normal routine for decrease processing effort and reduce the rendering process. if you want to know when a tab1 resized, reimplement(override) resizeEvent and say to tab2 must be resized.

Upvotes: 1

Related Questions