2 comboBoxes Show Hide one Button .
-
i have 2 combo boxes each containing 4 elements , I want to show a button if the fourth element is selected in either of the two , and Hide the button if there is no selection for the fourth element in any of them .
void MainWindow::on_Combobox1_currentIndexChanged(int index) { if(index == 3) { ui->button->show(); } else { ui->button->hide(); } } void MainWindow::on_Combobox2_currentIndexChanged(int index) { if(index == 3) { ui->button->show(); } else { ui->button->hide(); } }
but this hide the button if i select first the element 4 in ComboBox1 and
then select any element Except 4 Combobox2 (in this case indeed the button appear)
thanks, -
@Marco-Flad hi
void MainWindow::on_Combobox1_currentIndexChanged(int index) { if(index == 3) { ui->button->show(); } else if( /*check the other combobox* index !=3 */ ){ ui->button->hide(); } }
-
@Marco-Flad
So if you think it through you need to know the state of both selections in order to make your decision. You could do it various ways. Might as well just have one slot which they both use:void MainWindow::on_Combobox1_or_2_currentIndexChanged(int index) { if(ui->combobox1.currentIndex() == 3 || ui->combobox2.currentIndex() == 3) { ui->button->show(); } else { ui->button->hide(); } }
If you want to keep separate slots for each one, you'll still want the slots to examine the other one's
currentIndex()
. -
@LeLev hi , Thank its works .
-
@Marco-Flad said in 2 comboBoxes Show Hide one Button .:
i don't Know how to make one Slot activated when any of combo boxes selected ?
Just connect both combo signals to same slot.
Since it looks you're using auto-connection feature, I guess you need a "bridge", pseudo-code::void MainWindow::on_Combobox1_currentIndexChanged(int index) { on_AnyCombo_currentIndexChanged(index); } void MainWindow::on_Combobox2_currentIndexChanged(int index) { on_AnyCombo_currentIndexChanged(index); } void MainWindow::on_AnyCombo_currentIndexChanged(int index) { // code suggested by @JonB }
-
@Pablo-J-Rogina said in 2 comboBoxes Show Hide one Button .:
Just connect both combo signals to same sl
thanks its good