PDA

View Full Version : ComboBox with multiple columns



haldrik
24th August 2008, 01:37
Is possible create or get a ComboBox with multiple columns? like Visual Basic does.

for example to show the result of a QSqlQuery with more than one column.

spirit
24th August 2008, 07:57
did you search by forum? I've posted answer on this question.

SunnySan
11th September 2008, 12:50
Did you find an answer ?
I m also looking to put multiple column to the comboBox. I search the forum but didn't find anything to help my need.

Does anybody have a good example?
Thanks

haldrik
11th September 2008, 16:08
I have searched on forum, finded about ItemDelegate but must read the documentation. You can read docs and the QT-4.3 book.

wysota
11th September 2008, 17:38
The funny thing is I implemented a multicolumn combobox today :) It's about 10 lines of code in total ;)

haldrik
11th September 2008, 23:35
Ok, show us the code ;), and could you add some comments?

wysota
11th September 2008, 23:58
I can't :) But I can tell you that all you need to do is replace (using setView()) the default view (which is a QListView) of the combobox with a multicolumn one like QTreeView and optionally reimplement showPopup() to setup the geometry of the popup widget (you will probably want to make it wider than the combobox). Oh... and remember to use a multicolumn model with the widget :)

olosie
11th July 2009, 11:15
example:

QTableView *tv = new QTableView(this);
tv->setModel( model );
tv->horizontalHeader()->setVisible(false);
tv->verticalHeader()->setVisible(false);
tv->resizeColumnsToContents();
combo->setView(tv);