Nominate our 2022 Qt Champions!

Adding widget to invisible layout won't make it update

  • Hi all,

    I have a specific problem with layout updates.
    My application shows a TabWidget with multiple tabs. One of this tabs shows a "preview" area of what I'm editing (a QScrollArea with the previewed thing inside). The preview area is layed out with other widgets on the same tab.

    I have an "attach"/"detach" button that when clicked removes the preview area and makes it a top level window (with reparent()). "attach" re-attaches the preview area by inserting it in the layout again. The preview area is also automaticallty re-attached when it is closed through the window manager.

    The problem: as soon as the tab that contains the preview area is visible, reattaching is done well: I see the preview area in the layout, updates are done and it pushes other widgets with regards to its size policy.

    If the tab is not visible (switched to another tab), when I close the preview window then switch to the tab where it is re-attached, I don't see the preview area. Seems like layout recalculation is not done if the layout is not visible.

    I tried all the layout->update()|invalidate()|activate() stuff with no success.

    Do you have any ideas about this ?

    Thank you.

  • Lifetime Qt Champion


    You should also add which version of Qt and OS you are currently using

  • I use Qt 4.8.5 on Linux (Kubuntu prebuilt packages)

    I tried to activate the tab programmatically before re-attaching the preview and it worked.

  • Lifetime Qt Champion

    So you bring back the right tab, attach the preview and the switch back to the tab that was selected before ?

  • Extacly :) This seems to cause no flicker (how is this possible ?).

    That's strange because when designer generates code, it does not switch tabs before adding tab widgets. But that's another use case because it first populates the tab then adds it to the tab widget.

  • Lifetime Qt Champion

    Maybe because your machine is fast enough ;)

Log in to reply