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. How to remove item from Layout neatly

How to remove item from Layout neatly

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 946 Views 2 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.
  • A Offline
    A Offline
    Ahmed Zeid
    wrote on last edited by
    #1

    I have built this input window (see attached picture 1) with a bunch of QlineEdits and Qlabels inside nested layouts inside a QscrollArea in Qt Designer (notice that there are more widgets below the "Second Shaft Segment" label).
    When I use hide() to hide the "Second Shaft Segment" label and the widgets below it, attached picture 2 occurs (Notice the gap in the top portion which is also matched at the bottom of the scroll area).
    How to get the QscrollArea to shrink back to its original size, maintaning the original vertical spacing between my currently-shown widgets?

    What I tried: I tried to programmatically set the layout spacings back to the original status right after the hide() command, but that didn't work.

    1.png 2.png

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

      Why not use a single QGridLayout ?

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

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

        Hi,

        How are you building that widget ?

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Ahmed Zeid
          wrote on last edited by
          #3

          Hello, thank you for your reply.
          I am sorry I am not sure I understand your question. Can you rephrase please?

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

            How are you nesting these widgets ?

            From the looks of it you seem to have two layouts on top of each other but not inside a QVBoxLayout which could explain why you get the result you have.

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

            A 1 Reply Last reply
            0
            • SGaistS SGaist

              How are you nesting these widgets ?

              From the looks of it you seem to have two layouts on top of each other but not inside a QVBoxLayout which could explain why you get the result you have.

              A Offline
              A Offline
              Ahmed Zeid
              wrote on last edited by Ahmed Zeid
              #5

              @SGaist
              I basically have 2 gridLayouts (one for each column) both inside a horizontal layout.
              Adding them inside a Qframe seemed to solve the top and bottom gap. However, now my columns look like the attached picture (not of equal length kind of) although they contain the same number of widgets with the same fixed min and max height (attached picture).
              Sorry if my problem seemed too vague or unreproducible.

              Screenshot2.png

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

                Why not use a single QGridLayout ?

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

                A 1 Reply Last reply
                2
                • SGaistS SGaist

                  Why not use a single QGridLayout ?

                  A Offline
                  A Offline
                  Ahmed Zeid
                  wrote on last edited by
                  #7

                  @SGaist
                  It was because my columns are not equally distanced, but I took your recommendation and built my widgets in one QgridLayout and it worked perfectly! (After morphing it into Qframe to solve the top and bottom gap issue).
                  (I used empty labels as spacers between my two columns)

                  Two more questions please, my last row is initially hidden, when I show it by clicking a button, my scroll bar stays in previous place, can I have it go to the new bottom automatically instead?
                  Also, when I re-hide that last row also using a button, my scroll bar jumps to the top instead of going to the new bottom. Can I get it to go to new bottom instead?

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

                    Not knowing how you setup your QScrollArea, I can't answer.

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

                    1 Reply Last reply
                    0
                    • nageshN Offline
                      nageshN Offline
                      nagesh
                      wrote on last edited by
                      #9

                      @Ahmed-Zeid Try using TabWidget for showing the same repetitive entry of values related to "Second Shaft Segment" .

                      Two more questions please, my last row is initially hidden, when I show it by clicking a button, my scroll bar stays in previous place, can I have it go to the new bottom automatically instead?
                      Also, when I re-hide that last row also using a button, my scroll bar jumps to the top instead of going to the new bottom. Can I get it to go to new bottom instead?
                      

                      Scroll Area has alignment property can be set as setAlignment(Qt::Alignment) for aligning Qt::AlignTop or Qt::AlignBottom

                      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