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. Problem with splitters and layouts
Forum Updated to NodeBB v4.3 + New Features

Problem with splitters and layouts

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 648 Views 3 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.
  • J Offline
    J Offline
    james b-s
    wrote on last edited by james b-s
    #1

    I have a dialog that was working. I have a QGridLayout called overallLayout. This layout contains a QVBoxLayout called leftLayout. leftLayout contains three QGridLayouts called topLayout, middleLayout, and bottomLayout. overallLayout is tied to the leftLayout with this line of code

    overallLayout->addLayout(leftLayout, 0, 0, -1, 0);
    

    That all works,

    I want to add a splitter so that everything in the left layout is to the left and there is more stuff on the right, with the splitter between the two.

    I create a rightWidget. I put a rightLayout within the rightWidget and then a button in that rightLayout. I then add a splitter to the overallLayout and add leftWidget and rightWidget to the splitter.

    Two things happen. 1. When I display the dialog, it is displayed too small. I can manually expand it and it has all the widgets, but the initial display is not big enough to show most of the left side and bottom of the stuff to the left of the splitter, and the right side is not displayed at all. Until I manually expand it.

    1. The splitter doesn't work. When I try to drag it left or right, the display vibrates until I slide it far enough and the right or left side disappears.

    I can't figure out what is wrong.

    The new code looks like this

    m_splitter = new QSplitter(this);
    
    m_leftWidget = new QWidget(m_splitter);
    m_leftWidget->setLayout(leftLayout);
    
    m_rightWidget = new QWidget(m_splitter);
    auto rightLayout = new QGridLayout;
    m_rightWidget->setLayout(rightLayout);
    
    auto button = new QPushButton("11111111111111111111111111111111");
    rightLayout->addWidget(button, 0, 0, -1, 0);
    
    m_splitter->addWidget(m_leftWidget);
    m_splitter->addWidget(m_rightWidget);
    m_splitter->setCollapsible(0, true);
    m_splitter->setCollapsible(1, true);
    m_splitter->setStretchFactor(1, 1);
    
    overallLayout->addWidget(m_splitter);
    

    I know there is some simplification that can be done. That will happen once this is working. Any suggestions on either problem listed above would be appreciated.

    Pl45m4P R J 3 Replies Last reply
    0
    • J james b-s

      I have a dialog that was working. I have a QGridLayout called overallLayout. This layout contains a QVBoxLayout called leftLayout. leftLayout contains three QGridLayouts called topLayout, middleLayout, and bottomLayout. overallLayout is tied to the leftLayout with this line of code

      overallLayout->addLayout(leftLayout, 0, 0, -1, 0);
      

      That all works,

      I want to add a splitter so that everything in the left layout is to the left and there is more stuff on the right, with the splitter between the two.

      I create a rightWidget. I put a rightLayout within the rightWidget and then a button in that rightLayout. I then add a splitter to the overallLayout and add leftWidget and rightWidget to the splitter.

      Two things happen. 1. When I display the dialog, it is displayed too small. I can manually expand it and it has all the widgets, but the initial display is not big enough to show most of the left side and bottom of the stuff to the left of the splitter, and the right side is not displayed at all. Until I manually expand it.

      1. The splitter doesn't work. When I try to drag it left or right, the display vibrates until I slide it far enough and the right or left side disappears.

      I can't figure out what is wrong.

      The new code looks like this

      m_splitter = new QSplitter(this);
      
      m_leftWidget = new QWidget(m_splitter);
      m_leftWidget->setLayout(leftLayout);
      
      m_rightWidget = new QWidget(m_splitter);
      auto rightLayout = new QGridLayout;
      m_rightWidget->setLayout(rightLayout);
      
      auto button = new QPushButton("11111111111111111111111111111111");
      rightLayout->addWidget(button, 0, 0, -1, 0);
      
      m_splitter->addWidget(m_leftWidget);
      m_splitter->addWidget(m_rightWidget);
      m_splitter->setCollapsible(0, true);
      m_splitter->setCollapsible(1, true);
      m_splitter->setStretchFactor(1, 1);
      
      overallLayout->addWidget(m_splitter);
      

      I know there is some simplification that can be done. That will happen once this is working. Any suggestions on either problem listed above would be appreciated.

      J Offline
      J Offline
      james b-s
      wrote on last edited by
      #5

      @james-b-s
      The problem turned out to be the initialization of overallLayout. The parent was not passed in. The interesting thing is that the dialog worked fine without the parent until I added the splitter and the right side. Evidently, there is something about the splitter that requires that its parent have a valid parent. The problem wasn't even in any of the code that I was adding.

      This is version qt version 5.12

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

        Hi,

        Can you provide a complete minimal compilable example that shows your issue ?

        Also, which version of Qt are you using ?
        On which platform ?

        On a side note, since you are putting all your widgets in layouts or the splitter, there's no need to give them parent at construction time as they are going to be reparented anyway when setting them in said layouts or QSplitter.

        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
        • J james b-s

          I have a dialog that was working. I have a QGridLayout called overallLayout. This layout contains a QVBoxLayout called leftLayout. leftLayout contains three QGridLayouts called topLayout, middleLayout, and bottomLayout. overallLayout is tied to the leftLayout with this line of code

          overallLayout->addLayout(leftLayout, 0, 0, -1, 0);
          

          That all works,

          I want to add a splitter so that everything in the left layout is to the left and there is more stuff on the right, with the splitter between the two.

          I create a rightWidget. I put a rightLayout within the rightWidget and then a button in that rightLayout. I then add a splitter to the overallLayout and add leftWidget and rightWidget to the splitter.

          Two things happen. 1. When I display the dialog, it is displayed too small. I can manually expand it and it has all the widgets, but the initial display is not big enough to show most of the left side and bottom of the stuff to the left of the splitter, and the right side is not displayed at all. Until I manually expand it.

          1. The splitter doesn't work. When I try to drag it left or right, the display vibrates until I slide it far enough and the right or left side disappears.

          I can't figure out what is wrong.

          The new code looks like this

          m_splitter = new QSplitter(this);
          
          m_leftWidget = new QWidget(m_splitter);
          m_leftWidget->setLayout(leftLayout);
          
          m_rightWidget = new QWidget(m_splitter);
          auto rightLayout = new QGridLayout;
          m_rightWidget->setLayout(rightLayout);
          
          auto button = new QPushButton("11111111111111111111111111111111");
          rightLayout->addWidget(button, 0, 0, -1, 0);
          
          m_splitter->addWidget(m_leftWidget);
          m_splitter->addWidget(m_rightWidget);
          m_splitter->setCollapsible(0, true);
          m_splitter->setCollapsible(1, true);
          m_splitter->setStretchFactor(1, 1);
          
          overallLayout->addWidget(m_splitter);
          

          I know there is some simplification that can be done. That will happen once this is working. Any suggestions on either problem listed above would be appreciated.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #3

          @james-b-s said in Problem with splitters and layouts:

          1. When I display the dialog, it is displayed too small. I can manually expand it and it has all the widgets, but the initial display is not big enough to show most of the left side and bottom of the stuff to the left of the splitter, and the right side is not displayed at all. Until I manually expand it.

          Is overallLayout the actual base layout of your dialog? From your description one can assume that you have elements floating around which are not resized with the dialog.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • J james b-s

            I have a dialog that was working. I have a QGridLayout called overallLayout. This layout contains a QVBoxLayout called leftLayout. leftLayout contains three QGridLayouts called topLayout, middleLayout, and bottomLayout. overallLayout is tied to the leftLayout with this line of code

            overallLayout->addLayout(leftLayout, 0, 0, -1, 0);
            

            That all works,

            I want to add a splitter so that everything in the left layout is to the left and there is more stuff on the right, with the splitter between the two.

            I create a rightWidget. I put a rightLayout within the rightWidget and then a button in that rightLayout. I then add a splitter to the overallLayout and add leftWidget and rightWidget to the splitter.

            Two things happen. 1. When I display the dialog, it is displayed too small. I can manually expand it and it has all the widgets, but the initial display is not big enough to show most of the left side and bottom of the stuff to the left of the splitter, and the right side is not displayed at all. Until I manually expand it.

            1. The splitter doesn't work. When I try to drag it left or right, the display vibrates until I slide it far enough and the right or left side disappears.

            I can't figure out what is wrong.

            The new code looks like this

            m_splitter = new QSplitter(this);
            
            m_leftWidget = new QWidget(m_splitter);
            m_leftWidget->setLayout(leftLayout);
            
            m_rightWidget = new QWidget(m_splitter);
            auto rightLayout = new QGridLayout;
            m_rightWidget->setLayout(rightLayout);
            
            auto button = new QPushButton("11111111111111111111111111111111");
            rightLayout->addWidget(button, 0, 0, -1, 0);
            
            m_splitter->addWidget(m_leftWidget);
            m_splitter->addWidget(m_rightWidget);
            m_splitter->setCollapsible(0, true);
            m_splitter->setCollapsible(1, true);
            m_splitter->setStretchFactor(1, 1);
            
            overallLayout->addWidget(m_splitter);
            

            I know there is some simplification that can be done. That will happen once this is working. Any suggestions on either problem listed above would be appreciated.

            R Offline
            R Offline
            Robert Hairgrove
            wrote on last edited by
            #4

            @james-b-s I was having similar difficulties some time ago but solved the problem by using QFrame's to hold the layouts for the individual panels. I'm not sure that it makes any difference, though. My problem was that I was trying to add the layouts directly to the splitter, which is not allowed according to the documentation for QSplitter.

            Another thing I noticed from the code you have shown is that you create the widgets with the splitter as parent. I would not do this because when you call QSplitter::addWidget(), the splitter automatically becomes the parent of the widget given.

            Try setting it up in Qt Designer and look at the generated code?

            1 Reply Last reply
            0
            • J james b-s

              I have a dialog that was working. I have a QGridLayout called overallLayout. This layout contains a QVBoxLayout called leftLayout. leftLayout contains three QGridLayouts called topLayout, middleLayout, and bottomLayout. overallLayout is tied to the leftLayout with this line of code

              overallLayout->addLayout(leftLayout, 0, 0, -1, 0);
              

              That all works,

              I want to add a splitter so that everything in the left layout is to the left and there is more stuff on the right, with the splitter between the two.

              I create a rightWidget. I put a rightLayout within the rightWidget and then a button in that rightLayout. I then add a splitter to the overallLayout and add leftWidget and rightWidget to the splitter.

              Two things happen. 1. When I display the dialog, it is displayed too small. I can manually expand it and it has all the widgets, but the initial display is not big enough to show most of the left side and bottom of the stuff to the left of the splitter, and the right side is not displayed at all. Until I manually expand it.

              1. The splitter doesn't work. When I try to drag it left or right, the display vibrates until I slide it far enough and the right or left side disappears.

              I can't figure out what is wrong.

              The new code looks like this

              m_splitter = new QSplitter(this);
              
              m_leftWidget = new QWidget(m_splitter);
              m_leftWidget->setLayout(leftLayout);
              
              m_rightWidget = new QWidget(m_splitter);
              auto rightLayout = new QGridLayout;
              m_rightWidget->setLayout(rightLayout);
              
              auto button = new QPushButton("11111111111111111111111111111111");
              rightLayout->addWidget(button, 0, 0, -1, 0);
              
              m_splitter->addWidget(m_leftWidget);
              m_splitter->addWidget(m_rightWidget);
              m_splitter->setCollapsible(0, true);
              m_splitter->setCollapsible(1, true);
              m_splitter->setStretchFactor(1, 1);
              
              overallLayout->addWidget(m_splitter);
              

              I know there is some simplification that can be done. That will happen once this is working. Any suggestions on either problem listed above would be appreciated.

              J Offline
              J Offline
              james b-s
              wrote on last edited by
              #5

              @james-b-s
              The problem turned out to be the initialization of overallLayout. The parent was not passed in. The interesting thing is that the dialog worked fine without the parent until I added the splitter and the right side. Evidently, there is something about the splitter that requires that its parent have a valid parent. The problem wasn't even in any of the code that I was adding.

              This is version qt version 5.12

              Pl45m4P 1 Reply Last reply
              0
              • J james b-s has marked this topic as solved on
              • J james b-s

                @james-b-s
                The problem turned out to be the initialization of overallLayout. The parent was not passed in. The interesting thing is that the dialog worked fine without the parent until I added the splitter and the right side. Evidently, there is something about the splitter that requires that its parent have a valid parent. The problem wasn't even in any of the code that I was adding.

                This is version qt version 5.12

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #6

                @james-b-s said in Problem with splitters and layouts:

                The problem turned out to be the initialization of overallLayout. The parent was not passed in

                That's what I said here:

                @Pl45m4 said in Problem with splitters and layouts:

                Is overallLayout the actual base layout of your dialog? From your description one can assume that you have elements floating around which are not resized with the dialog.

                -> the layout was not applied to the dialog either with setLayout(overallLayout); or by making the dialog a direct parent of the main layout (i.e. overallLayout).


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                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