ChrisM
ChrisM

Reputation: 135

Changing buttons on button click

I have a ui I am working on, and I am trying to get the available buttons to change when I press one of the current buttons. For example, if buttons 1-9 are shown, if I press button 2, I want buttons 10-13 to show and buttons 1-9 to disappear. I am using qtdesigner, but I can hardcode this if needbe, I just dont know how to get this without opening and closing the entire window

Here are my buttons:

Buttons

Thanks!

Upvotes: 0

Views: 1456

Answers (1)

yurisnm
yurisnm

Reputation: 1640

The easiest way to do that is,

  1. Have the layout you need set up.
  2. Add all the (N) buttons to the layout itself from the very beginning.
  3. Initially hide the buttons you don't want to show up.
  4. 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:

  1. Add the button you need to your layout.

layout.addWidget(btn)

  1. 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.

Upvotes: 1

Related Questions