October 21, 2010

QtK QtK
Lab Rat
1140 posts

How do we rearrange widgets added to a Grid Layout at runtime?

 

How do we rearrange or remove a widget added to QGridLayout in runtime. Say in portrait mode I wish to show two labels each in two rows and in landscape mode it should change to all four labels in single row.

10 replies

October 21, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

AFAIK using Grid Layout it can be done only manually (so you need to manually catch mode change and rearrange elements). Maybe QML is an option? It can be done slighlty easy there.

October 21, 2010

QtK QtK
Lab Rat
1140 posts

I can detect mode change. But how to rearrange the labels inside gridlayout. I couldn’t locate any api for removing or rearranging the widgets added in the GridLayout.

QML is still in its early stages so don’t want to try that now.

October 21, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

You can use two different layouts for landscape and portrait modes I think. No idea about other ways, I’m using qml for mobile UIs and it fits all my needs :).

October 22, 2010

QtK QtK
Lab Rat
1140 posts

If using two different layouts, how should we switch it. Can we hide a layout and all its controls.

October 22, 2010

lyuts lyuts
Lab Rat
169 posts
QtK wrote:
If using two different layouts, how should we switch it. Can we hide a layout and all its controls.

Do you want to keep 2 different layouts and then switch them by just hiding one and showing the other?

 Signature 

I’m a rebel in the S.D.G.

October 22, 2010

QtK QtK
Lab Rat
1140 posts

I don’t prefer that but still would like to know how to do that if that is possible.

October 22, 2010

ZapB ZapB
Robot Herder
1359 posts

When you detect the mode change, call a slot that uses QLayout::removeWidget() to remove your widgets. Then add them to your new layout and finally set the new layout on the parent widget.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

October 22, 2010

QtK QtK
Lab Rat
1140 posts

Thank you, I was looking for something like QLayout::removeWidget(). I will try something like what you have suggested above.

Also is there any other better solution available for handling orientation change.

October 22, 2010

ZapB ZapB
Robot Herder
1359 posts

Have you seen this blog [labs.qt.nokia.com] entry from last year? I really would like ot see this functionality included into Qt but you might be able to get the code for this research project somewhere.

I am also interested in tracking this down. If I find it I’ll post a comment on here too.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

October 23, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts
QtK wrote:
Thank you, I was looking for something like QLayout::removeWidget()

you could alternatively use QLayout::removeItem(), and then add them back with QLayout::addItem().. you probably already also know this by now :)

 
  ‹‹ Will in any of the future version it be possible to style the status pane and CBA controls using Qt.      QObject creating in one thread using in other ››

You must log in to post a reply. Not a member yet? Register here!