[solved] How to make cell in the Table View a QCombobox when an user edits ?
-
-
@Sam
I tried with QStandardItemModel . But i want tableview be the combobox when edited.MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QStandardItemModel *model = new QStandardItemModel(4,2,this); ui->tableView->setModel(model); for(int row = 0; row < 4; row++) { for(int col = 0; col < 2; col++) { QModelIndex index= model->index(row,col,QModelIndex()); // 0 for all data model->setData(index, 0) ; } } QComboBox *combo = new QComboBox(this); combo->setModel(model); }
-
@Sam
I have 2 column and 4 rows if i setview->setItemDelegateForColumn(1,comboDelegate );
Entire column "1 " will be a combobox .
If i set
view->setItemDelegateForRow(1,comboDelegate );
only row 1 corresponding to first column will be combobox (one cell only )
What if i want only one row to be a combobox? -
So you mean to say you want to display the combobox only for one specific cell, In this case you can also try with setIndexWidget() which will display a combobox for a particular modelIndex.
-
@Sam
Thanks you :)
Why can't i set using? can't we do it for tableview? is it only for widgets?tableView->setIndexWidget(index,comboDelegate);
'QAbstractItemView::setIndexWidget' : cannot convert parameter 2 from 'ComboBoxDelegate *' to 'QWidget *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
This works fine
tableView->setIndexWidget(index,new QLineEdit);