The easiest way to do that is,
- Have the layout you need set up.
- Add all the (N) buttons to the layout itself from the very beginning.
- Initially hide the buttons you don't want to show up.
- When clicking in the button you want, hide the buttons you want to disappear and show the buttons you want to appear.
Obs: Remember that when hiding the buttons all of the other will adjust itself according to the layout's policies.
Another way to do that would be really adding and removing the buttons you need:
- Add the button you need to your layout.
layout.addWidget(btn)
- When you want to remove the button
layout.removeWidget(btn)
btn.hide()
btn.close()
del btn
Obs: you will have to struggle a bit more adding and removing the buttons from your layout but that's how it is.
There is also the option of instead of putting all the buttons in layouts you divide it in groups and put it in another widget(making it as layers) so when you have to remove certain amount of buttons you just remove that widget and all from that will be gone with it. Also you can have a look in ButtonGroup and see if it'd serve you for something.