I'm trying to display one of two layouts depending on whether a checkbox is checked or not.
Only using widgets I can do the following which works fine: (each widget in this example is a QLineEdit)
myCheckbox.stateChanged.connect(switchControls)
def switchControls (self, state):
if state == 2:
self.widget1.show()
self.widget2.hide()
else:
self.widget1.hide()
self.widget2.show()
However, since I want to add a descriptive label to each QLineEdit, I need to combine a QLineEdit+QLabel in a layout or container of some kind. I have been trying the addlayout / removeLayout / removeItem to do the above on layouts instead of widgets, but can't get it to work. The program crashed on my last try.
What is the easiest way to switch between two layouts? It doesn't have to use a checkbox but I'd prefer that.
Put the layouts into separate widgets. Now you're "only using widgets".
Here's an example:
Run it to see how it works.