[Development] Feature request: several layouts in a single ui file

Sze Howe Koh szehowe.koh at gmail.com
Sun Sep 1 05:49:06 CEST 2013


On 1 September 2013 05:27, Yves Bailly <yves.bailly at laposte.net> wrote:
> On 31/08/2013 14:42, Mark wrote:
>> A nice way to load different gui versions is by combining states [1]
>> and the loader object [2] and just load the gui you want based on the
>> state you set.
>>
>> [1] http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-state.html
>> [2] http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-loader.html
>
> If I understand things correctly, using the loader is a bit like
> "destroy the current GUI" followed by "rebuild a new GUI".
>
> What I'm looking for is quite different: it's out of question to
> *destroy* widgets, just change their layout - only the layouts are
> destroyed, not the widgets. Imagine the case where a displayed
> component needs a lot of time to build its contents, either from
> user inputs or some long computation.
>
> All of this re-layouting should be completely dynamic, done and
> un-done several time during the application running time.
>
> Or am I missing something?

You can achieve that with traditional QWidgets without destroying and
reconstructing any objects.

QLayout::addWidget() can transfer a widget from one layout to another.
Transfer your widgets, then call QWidget::setLayout() to use the new
layout.  At this point, you can destroy your old layout or keep it in
memory for reuse, it doesn't really matter. Repeat the procedure to
switch back to your first layout.

Alternatively, use QLayout::removeWidget() to remove widgets without
destroying them. Then, use QLayout::addWidget() to re-add them in a
different arrangement.


Regards,
Sze-Howe



More information about the Development mailing list