Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    Mobile and Embedded
    4
    11
    9170
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kamalakshantv last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • D
        DenisKormalev last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • K
          kamalakshantv last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • D
            DenisKormalev last edited by

            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 :).

            1 Reply Last reply Reply Quote 0
            • K
              kamalakshantv last edited by

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

              1 Reply Last reply Reply Quote 0
              • L
                lyuts last edited by

                [quote author="QtK" date="1287735292"]If using two different layouts, how should we switch it. Can we hide a layout and all its controls.[/quote]

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

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

                1 Reply Last reply Reply Quote 0
                • K
                  kamalakshantv last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • Z
                    ZapB last edited by

                    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.

                    Nokia Certified Qt Specialist
                    Interested in hearing about Qt related work

                    1 Reply Last reply Reply Quote 0
                    • K
                      kamalakshantv last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • Z
                        ZapB last edited by

                        Have you seen this "blog":http://labs.qt.nokia.com/2009/02/26/animated-layouts-with-qt-kinetic/ 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.

                        Nokia Certified Qt Specialist
                        Interested in hearing about Qt related work

                        1 Reply Last reply Reply Quote 0
                        • ?
                          Guest last edited by

                          [quote author="QtK" date="1287741731"]Thank you, I was looking for something like QLayout::removeWidget()[/quote]

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

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post