+ Reply to Thread
Results 1 to 2 of 2

Thread: Have dynamic combobox based on changes in another combobox

  1. #1
    Join Date
    Feb 2013
    Posts
    65
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Have dynamic combobox based on changes in another combobox

    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.

  2. #2
    Join Date
    Feb 2013
    Posts
    65
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Have dynamic combobox based on changes in another combobox

    I got it working using a connect slot and a better alternative method too. No need to reply.



    Added after 24 minutes:


    The connect slot solution is:

    Qt Code:
    1. connect(ui->comboBox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), this, &MainWindow::setGames);
    To copy to clipboard, switch view to plain text mode 

    An alternative and easier solution is:

    Qt Code:
    1. void MainWindow::on_comboBox_currentTextChanged(const QString &arg1)
    2. {
    3. if (arg1 == "first") {
    4. ui->comboBox_2->clear();
    5. ui->comboBox_2->addItem("1");
    6. }
    7. else if (arg1 == "second") {
    8. ui->comboBox_2->clear();
    9. ui->comboBox_2->addItem("2");
    10. }
    11. else if (arg1 == "third") {
    12. ui->comboBox_2->clear();
    13. ui->comboBox_2->addItem("3");
    14. }
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by te777; 17th April 2018 at 02:38.

+ Reply to Thread

Similar Threads

  1. how do I use comboBox
    By QT++ in forum Newbie
    Replies: 5
    Last Post: 2nd July 2013, 14:13
  2. Replies: 4
    Last Post: 28th August 2010, 13:17
  3. Help ComboBox
    By vinny gracindo in forum Newbie
    Replies: 3
    Last Post: 20th November 2009, 19:41
  4. Dynamic translation for ComboBox
    By Rakesh_Kumar in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2009, 11:27
  5. ComboBox of bmp:s
    By SailinShoes in forum Qt Programming
    Replies: 2
    Last Post: 5th March 2008, 15:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts