Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Easiest way to hide widget and spacing in QLayout



  • Hello.

    I have lauout with several buttons.

        auto buttonsLayout = new QHBoxLayout(buttonsWidget);
        button1 = new QPushButton(buttonsWidget);
        buttonsLayout->addSpacing(24);
    
        button2 = new QPushButton(buttonsWidget);
        buttonsLayout->addSpacing(24);
    
        button3 = new QPushButton(buttonsWidget);
        buttonsLayout->addSpacing(24);
    
        button4 = new QPushButton(buttonsWidget);
        buttonsLayout->addSpacing(24);
    

    And i want to hide button3. After that, i will have 2 spacers between button2 and button4. Is there the method to hide button3 with spacing simultaneously? What is the easiest way? I know i can find this space and hide it manually, but i hope there is exists automatically method.



  • since all the spacing is the same just remove all the buttonsLayout->addSpacing(24); and call buttonsLayout->setSpacing(24); just once. it will fix everything



  • since all the spacing is the same just remove all the buttonsLayout->addSpacing(24); and call buttonsLayout->setSpacing(24); just once. it will fix everything



  • Thanks, it works.


Log in to reply