What's the best way to change the UI based on the QComboBox index?
Solved
General and Desktop
-
So basically I need that my UI adapts to the index of the QCombomBox, and I done it creating all the widgets in the QtCreator and hiding or showing it depending on the index of the QComboBox, this is my code:
void MainWindow::on_c_tipo_currentIndexChanged(int index) { if(index == 0){ ui->s_numcomp->setHidden(false); ui->label_numcomp->setHidden(false); ui->t_rmv_teste->setHidden(false); ui->t_adc_teste->setHidden(false); ui->t_resposta_prog->setHidden(false); ui->t_resposta_mult->setHidden(true); ui->t_resposta_discursiva->setHidden(true); ui->t_adc_questao->setHidden(true); ui->t_rmv_questao->setHidden(true); } else if(index == 1){ ui->s_numcomp->setHidden(true); ui->label_numcomp->setHidden(true); ui->t_rmv_teste->setHidden(true); ui->t_adc_teste->setHidden(true); ui->t_resposta_mult->setHidden(false); ui->t_resposta_discursiva->setHidden(true); ui->t_resposta_prog->setHidden(true); ui->t_adc_questao->setHidden(false); ui->t_rmv_questao->setHidden(false); } else{ ui->s_numcomp->setHidden(true); ui->label_numcomp->setHidden(true); ui->t_rmv_teste->setHidden(true); ui->t_adc_teste->setHidden(true); ui->t_resposta_mult->setHidden(true); ui->t_resposta_discursiva->setHidden(false); ui->t_resposta_prog->setHidden(true); ui->t_adc_questao->setHidden(true); ui->t_rmv_questao->setHidden(true); } }
Is there a better way to do that? I'm new to Qt and this for me looks like i'm doing something wrong. Here's some pictures of the setup in the QtCreator and my program running.
-
-
Hi
Welcome to the forum.
As @jsulm says, StackedWidget is perfect if the combox flips between sort of pages.If that dont fit completely your use case, let us know as there are many ways to
control the widget besides manually hide /show :)