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. 2 comboBoxes Show Hide one Button .
Forum Updated to NodeBB v4.3 + New Features

2 comboBoxes Show Hide one Button .

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 562 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.
  • M Offline
    M Offline
    Marco Flad
    wrote on last edited by
    #1

    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,

    JonBJ 1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      @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();
          }   
      }
      
      M 1 Reply Last reply
      1
      • M Marco Flad

        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,

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @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().

        M 1 Reply Last reply
        1
        • ODБOïO ODБOï

          @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();
              }   
          }
          
          M Offline
          M Offline
          Marco Flad
          wrote on last edited by
          #4

          @LeLev hi , Thank its works .

          1 Reply Last reply
          0
          • JonBJ JonB

            @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().

            M Offline
            M Offline
            Marco Flad
            wrote on last edited by
            #5

            @JonB Hi,
            its a good solution when there is a lot of Combo-boxes but i don't Know how to make one Slot activated when any of combo boxes selected ?
            Thanks,

            Pablo J. RoginaP 1 Reply Last reply
            0
            • M Marco Flad

              @JonB Hi,
              its a good solution when there is a lot of Combo-boxes but i don't Know how to make one Slot activated when any of combo boxes selected ?
              Thanks,

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @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 
              }
              

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              M 1 Reply Last reply
              1
              • Pablo J. RoginaP Pablo J. Rogina

                @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 
                }
                
                M Offline
                M Offline
                Marco Flad
                wrote on last edited by
                #7

                @Pablo-J-Rogina said in 2 comboBoxes Show Hide one Button .:

                Just connect both combo signals to same sl
                thanks its good

                1 Reply Last reply
                0

                • Login

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