Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. a way to reset the layout?

a way to reset the layout?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 6.9k Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    qtpi
    wrote on last edited by
    #1

    hi folks. I am thinking about how I can reset the layout for my program. The possible solutions are: QStackedWidget/QStackedLayout or delete the layout and re-create new layout.

    But my question is: is there any way to just demount all the widgets and sublayouts from the main layout without deleting them? So in this case I do not need to re-initialize all the widgets and sublayouts.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Out of curiosity, why do you need that for ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Out of curiosity, why do you need that for ?

        Q Offline
        Q Offline
        qtpi
        wrote on last edited by
        #3

        @SGaist hi, I'm trying to make a changeable window layout. If the button is pressed the window layout will change from one form to another.

        I thought QStackedLayout is not good cause I have to create multiple instances for the windows then stack them together. My priority is the efficiency so this seems not very beneficial for me.

        I tried to delete the layout and re-create the layout. It worked, but the program seems so unstable. It will crash with no reason.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alex_malyu
          wrote on last edited by
          #4

          Combination of:
          void QLayout::removeItem(QLayoutItem *item)
          void QLayout::removeWidget(QWidget *widget)

          or if you only need widgets:
          QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options = Qt::FindChildrenRecursively)

          Even though I did not see a single case when such approach would provide any advantage it probably may exist.

          Q 1 Reply Last reply
          0
          • A alex_malyu

            Combination of:
            void QLayout::removeItem(QLayoutItem *item)
            void QLayout::removeWidget(QWidget *widget)

            or if you only need widgets:
            QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options = Qt::FindChildrenRecursively)

            Even though I did not see a single case when such approach would provide any advantage it probably may exist.

            Q Offline
            Q Offline
            qtpi
            wrote on last edited by
            #5

            @alex_malyu hi, thnx for the reply. The thing is every instance has a lots of update functions in it. If I create one more instance and just hide it using QStackedLayout, the update functions will still be called in background and it's not friendly for the RAM.

            maybe there's a way to re-write it so the update functions will only be called when the parents Widget is shown.

            A 1 Reply Last reply
            0
            • Q qtpi

              @alex_malyu hi, thnx for the reply. The thing is every instance has a lots of update functions in it. If I create one more instance and just hide it using QStackedLayout, the update functions will still be called in background and it's not friendly for the RAM.

              maybe there's a way to re-write it so the update functions will only be called when the parents Widget is shown.

              A Offline
              A Offline
              alex_malyu
              wrote on last edited by alex_malyu
              #6

              @qtpi
              look at QWidget::setUpdatesEnabled(
              call it on widget parent of layout you change, make changes, re-enable

              setUpdatesEnabled(false);
              bigVisualChanges();
              setUpdatesEnabled(true);

              Q 1 Reply Last reply
              1
              • A alex_malyu

                @qtpi
                look at QWidget::setUpdatesEnabled(
                call it on widget parent of layout you change, make changes, re-enable

                setUpdatesEnabled(false);
                bigVisualChanges();
                setUpdatesEnabled(true);

                Q Offline
                Q Offline
                qtpi
                wrote on last edited by
                #7

                @alex_malyu they look very interesting, I'm gonna do some research. Thanks for the help!

                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