Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How do we rearrange widgets added to a Grid Layout at runtime?

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

Scheduled Pinned Locked Moved Mobile and Embedded
11 Posts 4 Posters 10.0k Views
  • 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 Offline
    K Offline
    kamalakshantv
    wrote on last edited by
    #1

    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
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      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
      0
      • K Offline
        K Offline
        kamalakshantv
        wrote on last edited by
        #3

        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
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          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
          0
          • K Offline
            K Offline
            kamalakshantv
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lyuts
              wrote on last edited by
              #6

              [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
              0
              • K Offline
                K Offline
                kamalakshantv
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  ZapB
                  wrote on last edited by
                  #8

                  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
                  0
                  • K Offline
                    K Offline
                    kamalakshantv
                    wrote on last edited by
                    #9

                    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
                    0
                    • Z Offline
                      Z Offline
                      ZapB
                      wrote on last edited by
                      #10

                      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
                      0
                      • ? This user is from outside of this forum
                        ? This user is from outside of this forum
                        Guest
                        wrote on last edited by
                        #11

                        [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
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved