Unsolved Best way to change change Widgets on a layout depending on a value of a Qcombobox in a QFormLayout?
-
Im using a QFormLayout, where each row I have a Horizontal Layout. Inside this Layout I have a QComboBox and other widgets that depend on the value of the combo box. If for example the index of the combo box is 1 I have a QLineEdit, a check box and a label but if the index value of the combobox is changed the checkbox and label should be hidden or replaced by another widget.
The problem Im facing is that each time I change the Combobox I dont know in which row from the Formlayout the user has changed the value. Is there a method or member I can use from the combobox or formlayout to know this?
My current Idea is to just save the current index of each combobox and compare it again when the change has been done to know which combobox in the formlayout has been changed.
Is there another way to deal with this?
-
Hi and welcome to devnet,
Sounds like you should use a QStackedWidget. You can then connect the combo box indexChanged signal to the QStackedWidget::setCurrentIndex slot directly.
-
I would create a widget from the controls and instance the widget for every row. This way, the handling of showing/hiding/replacing of controls can happen internally in this widget and it doesn't even have to be aware of other instances in the other rows.
This can be combined with SGaist's method of swapping single controls within the widget.
Does that make sense?