There are several ways to achieve that. One extremely simple but not that dynamic way would be to check the column and row number in createEditor(). For example:
QWidget* MyItemDelegate
::createEditor(QWidget* parent,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
if (index.column() == 3 && index.row() > 2) {
...
return customEditor;
}
return 0; // or return QItemDelegate::createEditor(parent, option, index);
}
QWidget* MyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
if (index.column() == 3 && index.row() > 2) {
...
return customEditor;
}
return 0; // or return QItemDelegate::createEditor(parent, option, index);
}
To copy to clipboard, switch view to plain text mode
A bit more flexible way would be to use user roles to store the information:
tableWidgetItem->setData(Qt::UserRole, true);
QWidget* MyItemDelegate
::createEditor(QWidget* parent,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
if (index.data(Qt::UserRole).toBool() == true) {
...
return customEditor;
}
return 0; // or return QItemDelegate::createEditor(parent, option, index);
}
tableWidgetItem->setData(Qt::UserRole, true);
QWidget* MyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
if (index.data(Qt::UserRole).toBool() == true) {
...
return customEditor;
}
return 0; // or return QItemDelegate::createEditor(parent, option, index);
}
To copy to clipboard, switch view to plain text mode
You can also consider using item/cell widgets as already suggested, but just be aware that they don't really integrate to the model-view framework. They're just something laid by hand on top of views.
Bookmarks