Creating table in QcomboBox
Solved
General and Desktop
-
Hi and welcome to devnet,
You have two options:
- set a custom view using QComboBox::setView
- as @JonB wrote, use a custom QStyledItemDelegate
-
@devman MWE:
#include <QtWidgets> int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow w; QComboBox *combo = new QComboBox(&w); QStandardItemModel model(10, 3); model.setHorizontalHeaderLabels({"title", "name", "company"}); for(int i=0; i< model.rowCount(); ++i){ for(int j=0; j < model.columnCount(); ++j){ QStandardItem *it = new QStandardItem(QString("%1 - %2").arg(i).arg(j)); model.setItem(i, j, it); } } combo->setModel(&model); combo->setModelColumn(1); QTableView *view = new QTableView; combo->setView(view); view->setSelectionBehavior(QAbstractItemView::SelectRows); view->setFixedWidth(350); w.show(); return a.exec(); }