Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What's the best way to change the UI based on the QComboBox index?
Forum Updated to NodeBB v4.3 + New Features

What's the best way to change the UI based on the QComboBox index?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 353 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zero_emc
    wrote on last edited by
    #1

    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.
    creator.png
    discursiva.png multiplaescolha.png

    jsulmJ 1 Reply Last reply
    1
    • Z Zero_emc

      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.
      creator.png
      discursiva.png multiplaescolha.png

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Zero_emc Check https://doc.qt.io/qt-5/qstackedwidget.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Z 1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 :)

        Z 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Zero_emc Check https://doc.qt.io/qt-5/qstackedwidget.html

          Z Offline
          Z Offline
          Zero_emc
          wrote on last edited by
          #4

          @jsulm Thanks, I will look into it and try to put in my project!

          1 Reply Last reply
          0
          • mrjjM mrjj

            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 :)

            Z Offline
            Z Offline
            Zero_emc
            wrote on last edited by
            #5

            @mrjj I looked and I think is fits perfectly, thanks for the reply!

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved