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. Have dynamic combo box based on selections from another combo box

Have dynamic combo box based on selections from another combo box

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.9k Views
  • 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.
  • T Offline
    T Offline
    te777
    wrote on 16 Apr 2018, 22:28 last edited by
    #1

    My application currently has 2 comboboxes on the main form. The first combobox has 14 items, but 5 categories. I would like to list the categories in an additional combobox that I would place on the form above the 14 item combobox. Then populate dynamically the original 14 item combobox (doing a clear()) first) with items based on the category combox selection. I think I've found how to clear and add items, but I don't know how to connect the signal. Any help would be greatly appreciated. Thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AmrCoder
      wrote on 16 Apr 2018, 23:27 last edited by AmrCoder
      #2

      as i understand the question, you can use the currentTextChanged signal in the first combobox, or by index using currentIndexChanged signal and check the changed item and depend on that value you can update the second combobox on that item in the first combobox like this for example, using by text change which return a string of the current value in the first combobox

      void MainWindow::on_comboBox_currentTextChanged(const QString &arg1)
      {
          if (arg1 == "first") {
              ui->comboBox_2->clear();
              ui->comboBox_2->addItem("1");
          }
          else if (arg1 == "second") {
              ui->comboBox_2->clear();
              ui->comboBox_2->addItem("2");
          }
          else if (arg1 == "third") {
              ui->comboBox_2->clear();
              ui->comboBox_2->addItem("3");
          }
      
      }
      

      now whenever you change a value in the first comobox you will update the second one

      1 Reply Last reply
      4
      • T Offline
        T Offline
        te777
        wrote on 17 Apr 2018, 01:11 last edited by
        #3

        Thanks. I already got it working using a connect slot. But I'll try your method and see if it works. Thanks again for your help.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          te777
          wrote on 17 Apr 2018, 01:20 last edited by
          #4

          I tried your method. Works perfectly. Seems a little quicker than the connect method too. Thanks again.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pablo J. Rogina
            wrote on 18 Apr 2018, 18:33 last edited by
            #5

            @te777 if your issue is solved, please don't forget to mark your post as such. Thanks.

            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

            1 Reply Last reply
            0

            1/5

            16 Apr 2018, 22:28

            • Login

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