View Full Version : QTableView doesn't use delegate

11th December 2009, 16:34
I have a QTableView, a QSqlTableModel, and an QItemDelegate subclass. I create my model, and set that on the table view. I create my delegate, and call tableView->setItemDelegate(new MyDelegate());.

When my window display, the table does display the data from the SQL table. However, not a single method in my delegate is called. I implement
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;

and have a log statement as the first line in each method. None gets hit.

Is there something about the combination of thee three classes that make them incompatible? Am I missing something?


12th December 2009, 11:44
Please use the CODE tags next time since your code is not really readable.
And then you just reimplemented functions which came in action if you edit the data of a model. So while debuging, do you alter the data of your model?

1st February 2010, 10:36

I had the same kind of problem with my CustomModel and CustomDelegate. Problem was that I did not implemented the methods in the model to make it editable:

// For making the items editable
Qt::ItemFlags flags( const QModelIndex & index ) const;
bool setData (const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);

See QT documentation -> Model Subclassing Reference ->Editable items

Hope this helps.



1st February 2010, 10:45
Did you use QAbstractItemView::setEditTriggers ??
Normally the functions you mentioned in the first post will be called when editor is to be called.
An editor will be called if the item is editable and the triggers have been activated.