0

I am using QStandardItemModel inside QTtableview. Is it possible to add checkbox in on column cell & combobox in another column cell.

So that i can select predefined option from the combo box.

Please suggest how to achieve this.

enter image description here

Allan
  • 2,971
  • 4
  • 24
  • 28

1 Answers1

1

For the first:

You can setFlags() on an QStandardItem to make it checkable:

Qt::ItemFlags QStandardItem::flags() const
void QStandardItem::setFlags ( Qt::ItemFlags flags )
Qt::ItemIsUserCheckable

( enum Qt::ItemFlag )

For the second:

You should create your own Custom Delegate class inheriting QStyledItemDelegate and reimplement the createEditor, setEditorData and setModelData methods. Check this link and, for a more complete example, the SpinBox Delegate example

Edit: Once you got your custom delegate class, you have to tell your view to use it in a given column with QAbstractItemView::setItemDelegateForColumn

trompa
  • 1,967
  • 1
  • 18
  • 26