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



  • Thanks, it works.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.