multiple columns combobox
Unsolved
General and Desktop
-
why does this code not work for qt5.9 ? no item be selectted. i want to make 24 items to 2 columns, each item is clickable
the code comes from forum
ui->setupUi(this); QStandardItemModel model(5, 3); for(int i = 0; i < model.rowCount(); i++) { QStandardItem *col0 = new QStandardItem(QString("foobar%1").arg(i)); QStandardItem *col1 = new QStandardItem(QString("foo%1").arg(i)); QStandardItem *col2 = new QStandardItem(QString("bar%1").arg(i)); model.setItem(i, 0, col0); model.setItem(i, 1, col1); model.setItem(i, 2, col2); } ui->comboBox->setModel(&model); QTreeView *treeView = new QTreeView(ui->comboBox); ui->comboBox->setView(treeView); treeView->setColumnHidden(0, true); treeView->setSelectionBehavior(QAbstractItemView::SelectRows); treeView->setAllColumnsShowFocus(true); treeView->setRootIsDecorated(false); treeView->header()->hide();
-
Hi
The "treeView->setSelectionBehavior(QAbstractItemView::SelectRows);"
tell it to select whole rows, not cells.
Try with
QAbstractItemView::SelectItems -
well code worked for me so you must provide more details to "not work"
in order to help you. -
Shooting in the dark here but what about: http://doc.qt.io/qt-5/qcombobox.html#modelColumn-prop
The default is 0 and you hide that column
-
@Davidcheng said in multiple columns combobox:
could you show the code?
treeView->setModelColumn(1);