Hello all,
I would like to display a QComboBox in my QTableView.
I have tried to use the QItemDelegate, but it only shows it when I editing the cell.
Now I am using the QStyledItemDelegate in the following way:
{
painter->save();
switch(index.model()->data(index, Qt::UserRole).toInt()) {
case FuseBitField_boolean: {
editor->setGeometry(option.rect);
editor->render(painter);
} break;
case FuseBitField_enum: {
editor->setGeometry(option.rect);
editor->render(painter);
} break;
default:
return QStyledItemDelegate::paint(painter, option, index);
}
painter->restore();
}
void FuseDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
switch(index.model()->data(index, Qt::UserRole).toInt()) {
case FuseBitField_boolean: {
QCheckBox *editor = new QCheckBox();
editor->setGeometry(option.rect);
editor->render(painter);
} break;
case FuseBitField_enum: {
QComboBox *editor = new QComboBox();
editor->setGeometry(option.rect);
editor->render(painter);
} break;
default:
return QStyledItemDelegate::paint(painter, option, index);
}
painter->restore();
}
To copy to clipboard, switch view to plain text mode
But it does not displays anything. Editing works fine.
Is it possible to show a a widget with a delegate in non editing mode, or I should base my design on QTableWidget, and use addCellWidget()?
Bookmarks