Results 1 to 3 of 3

Thread: QComboBox extremely slow on adding a lot of items

  1. #1
    Join Date
    Mar 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QComboBox extremely slow on adding a lot of items

    Slowly started porting my App from MFC to QT (4.7.4) and came across a nasty problem ... I have a ComboBox with A LOT of items (6k approx), and while you can easily find the item by making the ComboBox editable and auto-select kicks in, the populating of it takes A LONG time (4 sec approx on my Quad-core Xeon), which is quite unacceptable (the same ComboBox in MFC fills up unnoticeable). So - a question is - what can I do to fill it up faster? I guess addItems with a QStringList might be faster, but I need the itemData with each item, as I use that as an index into other data associated with each entry.

    On the side-note is it possible to display the popup with items while entering the text in the QLineEdit of the QComboBox and move the selection on the popup according to data entered (more or less like the standard Windows ComboBox)?

    I know that selecting an item in a 6k list is not really friendly, but it is data, that is usually known by name, and can thus be found fast by starting to type it in. I could try to group the items by areas and add another combo to select the area first (and then populate the other ComboBox with a subset of items), but that would mean that the user has two steps to do, where one is preferred.

  2. #2
    Join Date
    Mar 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox extremely slow on adding a lot of items

    Time to answer my own question (in case someone else comes across the same problem) ... Actually came across a solution while trying to use QTableWidget (which performance is even WAY worse). Same story actually - DON'T work with addItem, as it's really slow. Creating a QStandardItemModel, populating it with data and then attaching the model to the QComboBox with setModel works much faster. Not perfect but at least 6 times faster in my case, which brings it down to much more tolerable (though not perfect) 1 second.

  3. #3
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QComboBox extremely slow on adding a lot of items

    Question is a bit old but I've found good solution (this question is quite high in proper google search).
    Problem is a view used for presenting items. For some reason QListView is buggy and create all items representations even if they are not visible.
    QTableView doesn't have such problem and it is possible to use this view in QComboBox: QComboBox::setView.
    This will work like a charm, only problem is that table must be tweaked to be visually acceptable:
    Qt Code:
    1. QTableView *table = new QTableView;
    2. table->horizontalHeader()->setVisible(false);
    3. table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    4. table->verticalHeader()->setVisible(false);
    5. this->ui->someComboBox->setView(table);
    To copy to clipboard, switch view to plain text mode 

  4. The following 2 users say thank you to MarekR22 for this useful post:

    anda_skoa (24th September 2013), toufic.dbouk (24th September 2013)

Similar Threads

  1. Qt Creator Debugging extremely slow
    By GMouzon in forum Qt Tools
    Replies: 4
    Last Post: 29th September 2015, 00:15
  2. Showing QGraphicsEllipseItems extremely slow
    By kalos80 in forum Qt Programming
    Replies: 5
    Last Post: 13th January 2010, 10:11
  3. Too slow adding & defining items to QTreeWidget
    By jnk5y in forum Qt Programming
    Replies: 16
    Last Post: 22nd April 2008, 21:26
  4. Adding QComboBox to QTableWidget very slow
    By munna in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2006, 16:45
  5. [QT3] QComboBox: Disable adding items on Enter-keypress
    By BrainB0ne in forum Qt Programming
    Replies: 7
    Last Post: 14th January 2006, 20:43

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.