Results 1 to 3 of 3

Thread: how to do chained selection

  1. #1
    Join Date
    Jan 2009
    Posts
    20
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default how to do chained selection

    I use QMultiHash for categories (keys) and subcategories (values). In a wizard page I want to have two QComboBox-es - the first for selecting a category (say - arts, education, engineering, leisure and sports, ...) and the second one for a subcategory (say, for engineering one could select civil, electrical, mechanical, ...).

    Of course, the values of the second combo box are determined by user's selection in the first one. How can I do that? It would be great if somebody could help with a simple example code.

    I suppose I need to use signals and slots, but after many hours of trying I still haven't managed to work it out. I'm a complete QT newbie and relatively new to C++.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to do chained selection

    Qt Code:
    1. // "QMultiHash for categories (keys) and subcategories (values)"
    2. QMultiHash<QString, QString> categoryHash;
    3.  
    4. // establish the connection
    5. connect(ui.categoryCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(setCategory(QString)));
    6.  
    7. // declared as a slot, of course
    8. void MyWindow::setCategory(const QString& category)
    9. {
    10. ui.subcategoryCombo->clear();
    11. QStringList subcategories = categoryHash.values(category);
    12. ui.subcategoryCombo->addItems(subcategories);
    13. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    xfurrier (14th January 2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    20
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: how to do chained selection

    Thanks for that, you are a star. How things look simple/obvious once you see the solution. I really don't understand how could've I spent so much time trying to solve my problem.

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 08:52
  2. Save & Restore a selection in QTreeWidget
    By youkai in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 20:54
  3. Replies: 0
    Last Post: 12th July 2008, 22:15
  4. QAbstractItemView selection behaviour issue
    By Caius Aérobus in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2007, 17:33
  5. CheckBox and selection in QTableView
    By Mike Krus in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2006, 21:31

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.