perform layout before window is shown?
-
I need to find the rectangles of some controls in my window, BEFORE the window is shown.
but it seems all rectangles have top-left as (0, 0), until i show the window, only THEN do they jump to the proper place.
my workaround is to briefly show-hide the window, THEN get the rectangles, THEN officially "show" the window.
so, how do i get the rectangles to update WITHOUT showing the window? here is my function:
void CWindow::UpdateLayout(bool via_hide_showB) { QWidget* qWidgetP(GetQtWind()); CF_ASSERT(qWidgetP); if (qWidgetP) { if (via_hide_showB) { QtWindow* qWindP(dynamic_cast<QtWindow*>(qWidgetP)); CF_ASSERT(qWindP); if (qWindP) { qWindP->Show(true); qWindP->Show(false); qWindP->i_did_hideshowB = true; } } else { QLayout* layoutP(qWidgetP->layout()); CF_ASSERT(layoutP); if (layoutP) { // these 2 cause the layout to run, so items // are now at their default sizes layoutP->update(); layoutP->activate(); // qWidgetP->dumpObjectTree(); } } } }
Note i'd LIKE to take the second block, but IT DOESN'T WORK, so i instead take the first block, which ALWAYS works, but it FLASHES the windows on the screen :(
-
This post is deleted!
-
Use your widgets's
showEvent
for this.
When this function is called, the widget is not yet shown but has its actual size/layout (geometry) already. -
@Pl45m4 said in perform layout before window is shown?:
Use your widgets's
showEvent
for this.how exactly? call it on the layoutP? iterate through every widget and call it on each one? i'm not sure what you mean.
i'm looking for one call for "make all my widgets know their rectangles", so that after that one call, NOT during an event handler, i can then ask any widget for its rectangle.
how do i do that?
-
@davecotter said in perform layout before window is shown?:
how exactly? call it on the layoutP?
Like this (in
QtWindow
class directly, not inCWindow
).void QtWindow:::showEvent(QShowEvent * event) { // do something with your "rectangles" here QWidget::showEvent(event); }
@davecotter said in perform layout before window is shown?:
i'm looking for one call for "make all my widgets know their rectangles", so that after that one call, NOT during an event handler, i can then ask any widget for its rectangle.
Mh... don't know if you can actively force the Qt widget to "show" without showing...
I know that inside the widgets c'tor the layouts and geometry / sizes are not correct, but during theshowEvent
they are.
So if you need to get any actual position or geometry before the widget appears on screen, theshowEvent
would be the right place. -
no you are not understanding. i do NOT want to show the window first. i want the rectangles updated when NO SHOW EVENT has been sent.
i'm not asking them to be shown, i'm asking them to update their rectangles. -
i need the rectangle info from ALL the widgets, BEFORE the WINDOW is shown.
Maybe i show it offscreen?? -
it sounds like you're saying that this sequence is a no-op when the window is hidden?
layoutP->update(); layoutP->activate();
-
@davecotter said in perform layout before window is shown?:
no you are not understanding. i do NOT want to show the window first. i want the rectangles updated when NO SHOW EVENT has been sent.
Yeah, after re-reading I understand... have edited my post.
You want something like this:
"Paint the widget" with its actual layout and size, without showing any of it.
There is no such function directly in Qt, but it can possibly be achieved with a workaround.
(which I unfortunately don't know right now) -
This post is deleted!
-