Results 1 to 8 of 8

Thread: how to add column in QComboBox??

  1. #1
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to add column in QComboBox??

    hey,
    I want to create a combobox havin 2 columns.Both the columns have different strings to show.
    how to do it??
    Plzz rep

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to add column in QComboBox??

    Use QComboBox::setView() to set a different view (a tree probably) for the combobox.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to add column in QComboBox??

    Thnxx for reply,
    can you plzz explain this a little more with the help of an example/code...
    waiting for ur rep..

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to add column in QComboBox??

    Qt Code:
    1. QComboBox *cb = new QComboBox;
    2. QAbstractItemModel *model = new SomeModel;
    3. cb->setModel(model);
    4. QTreeView *tv = new QTreeView;
    5. tv->setModel(model); // I don't know if this is required
    6. tv->header()->hide();
    7. cb->setView(tv);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to add column in QComboBox??

    hi,
    i hv written dis code but it is not showing the popup containing items.what is wrong in dis code??

    Qt Code:
    1. QComboBox *countryCombo=new QComboBox(this);
    2. countryCombo->setGeometry(42,25,205,25);
    3. countryCombo->setEditable(true);
    4. QStandardItemModel model(5, 3);
    5. for (int i = 0; i < model.rowCount(); ++i)
    6. {
    7. QStandardItem* col0 = new QStandardItem(QString("hh").arg(i));
    8. QStandardItem* col1 = new QStandardItem(QString("ee").arg(i));
    9. QStandardItem* col2 = new QStandardItem(QString("r").arg(i));
    10. model.setItem(i, 0, col0);
    11. model.setItem(i, 1, col1);
    12. model.setItem(i, 2, col2);
    13. }
    14. countryCombo->setModel(&model);
    15. QTreeView* treeView = new QTreeView(countryCombo);
    16. countryCombo->setView(treeView);
    17. treeView->setColumnHidden(0, true);
    18. treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
    19. treeView->setAllColumnsShowFocus(true);
    20. treeView->setRootIsDecorated(false);
    21. treeView->header()->hide();
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to add column in QComboBox??

    Your model goes out of scope before it has a chance to do anything.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to add column in QComboBox??

    hi,
    thanx for reply
    But I didnt got your point .pls explain with necessary change in the code .

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to add column in QComboBox??

    Allocate the model on heap and not on the stack.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  2. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  3. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 16:14
  4. Replies: 0
    Last Post: 10th November 2006, 13:46
  5. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00

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.