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. Why do my nested layouts overlap?
Forum Update on Monday, May 27th 2025

Why do my nested layouts overlap?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 1.1k 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.
  • T Offline
    T Offline
    tamirmichael
    wrote on last edited by
    #1

    Hello,

    This is the result of the code below:

    0_1556385628361_aa37a72d-34cd-493e-ad39-085bfb97ef6a-image.png

    bars_and_scrollbars_layout_ptr = new QGridLayout(this) ;
            bars_and_scrollbars_layout_ptr->setSpacing(6) ;
            bars_and_scrollbars_layout_ptr->addWidget(ui.qcustomplot_ptr, 0, 0, 3, 3) ;
            
    .....
    
    control_buttons_layout_ptr = new QGridLayout(this) ;
            control_buttons_layout_ptr->setSpacing(6) ;
    
    ....
    
    main_layout_ptr = new QVBoxLayout(this) ;
            main_layout_ptr->setSpacing(6) ; 
            main_layout_ptr->insertLayout(0, bars_and_scrollbars_layout_ptr) ;
            main_layout_ptr->insertLayout(1, control_buttons_layout_ptr) ;
            
    .....
    
    setLayout(main_layout_ptr) ;
    
    
    

    What I want to see is the layout that hosts the buttons (by the way only one is visible for some reason) below the chart.
    What a I forgetting?

    Thanks in advance!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #2

      Can't you use the designer for it? It even looks like you're already using a designer-created ui:

      ui.qcustomplot_ptr

      [Edit aha_1980: Fixed typo]

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • T Offline
        T Offline
        tamirmichael
        wrote on last edited by
        #3

        Hi,
        I prefer not using the designer.
        Any idea what's going on here?
        Thanks

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

          Hi,

          You are trying to assign every single one of your layouts to the widget. Using this in the constructor makes it equivalent to

          main_layout_ptr = new QGridLayout() ;
          setLayout(main_layout_ptr)
          

          It's likely not what you want.

          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
          3
          • T Offline
            T Offline
            tamirmichael
            wrote on last edited by
            #5

            Hi,

            I'm sorry I don't understand: What is it that you suggest I do to get vertical container embed 2 grid containers?

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

              Hi
              Nope he suggests you do not assign parent in the constructor of the sub-layouts. ( as i read it ;)

              bars_and_scrollbars_layout_ptr = new QGridLayout(this) ;
              control_buttons_layout_ptr = new QGridLayout(this) ;

              1 Reply Last reply
              1
              • T Offline
                T Offline
                tamirmichael
                wrote on last edited by
                #7

                Thank you.
                I am not sure though why this caused the issue above. I solved it by indeed removing "this" and indicating the column span for the buttons.
                But why does indicating parenthood cause this? I find this part to be much harder than in Python based GUI, for example...

                mrjjM 1 Reply Last reply
                0
                • T tamirmichael

                  Thank you.
                  I am not sure though why this caused the issue above. I solved it by indeed removing "this" and indicating the column span for the buttons.
                  But why does indicating parenthood cause this? I find this part to be much harder than in Python based GUI, for example...

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @tamirmichael
                  Hi
                  As @SGaist says
                  assigning a parent widget for the layout is a shortcut for doing

                  somelayout = new QGridLayout() ;
                  setLayout(somelayout);

                  Which is super when its standalone layout but as you have seen give strange side effects
                  if later assigned as sub-layout.

                  I use mostly Designer as its so quick to design even complex layouts so I didn't even spot it when looking
                  at your code.

                  1 Reply Last reply
                  3
                  • T Offline
                    T Offline
                    tamirmichael
                    wrote on last edited by
                    #9

                    Thank you all for the time and the effort !

                    mrjjM 1 Reply Last reply
                    1
                    • T tamirmichael

                      Thank you all for the time and the effort !

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @tamirmichael
                      Np :)
                      Please mark it as solved using the Topic button

                      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