Results 1 to 6 of 6

Thread: Sorting Combobox Items

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Sorting Combobox Items

    Hi,

    im inserting some items like this:
    Qt Code:
    1. QString path = ui.source_path_cb->currentText();
    2. QDir dir(path);
    3. QStringList list = dir.entryList(QDir::Files);
    4. for(unsigned i=0; i<list.count();i++){
    5. if(list[i]=="." || list[i]=="..") continue;
    6. ui.software_cb->insertItem(-1, list[i]);}
    To copy to clipboard, switch view to plain text mode 

    How could i sort my combobox?

    Think DigitalGasoline

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

    Default Re: Sorting Combobox Items

    See QComboBox::InsertPolicy.

    Edit: Oh, and there is also a filter called QDir::NoDotAndDotDot to skip those entries in the entry list...
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Sorting Combobox Items

    Hi,

    i tried all InsertPolicy options showing in the designer (for example insert Alphabeticaly ...), but i have the false sorting..

    w....a and not from a ... to w
    Think DigitalGasoline

  4. #4
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Sorting Combobox Items

    Can somebody help me to sort my combobox
    Think DigitalGasoline

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

    Default Re: Sorting Combobox Items

    You know, it's kind of impossible to say what's the problem without seeing any code. Anyway, here's two ways of listing files in an alphabetic order.

    1) using QComboBox::InsertAlphabetically:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char* argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QComboBox combo;
    7. combo.setInsertPolicy(QComboBox::InsertAlphabetically);
    8. combo.addItems(QDir("/home/jp").entryList(QDir::Files | QDir::NoDotAndDotDot));
    9. combo.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    2) using QDir::Name sort flag
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char* argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QComboBox combo;
    7. combo.addItems(QDir("/home/jp").entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name));
    8. combo.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Sorting Combobox Items

    Hi JPN,

    thank you very much!! It works

    I only tried to set the option in the designer "insert Alphabeticaly"..

    Thank u!!
    Think DigitalGasoline

Similar Threads

  1. Light items for the graphicsView
    By maverick_pol in forum Qt Programming
    Replies: 12
    Last Post: 1st November 2007, 18:51
  2. Occurance of Duplicate items in QComboBox
    By merry in forum Qt Programming
    Replies: 8
    Last Post: 12th September 2007, 15:05
  3. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20
  4. Sorting Tree items based on database properties
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2006, 19:44
  5. Creating events for combobox items
    By confused in forum Newbie
    Replies: 4
    Last Post: 26th March 2006, 16:40

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.