
Originally Posted by
jacek
There's a difference between having a specific editor for given cell and displaying that cell's content in specific way. Although both are handled by a delegate.
Thanks for your reply. Yes, that's where I started. It led to me finding openPersistentEditor() in the documentation, which seemed to be the nearest thing I could find to example/documentation of how to do what I wanted. But having found it, I cannot see how it should be used.
In general, if I understand the Model/View Programming documentation, you have a model which contains the data, separate from a combination of view and delegate which decide how to show the data.
Now, the delegate decides - after the model is complete - that a column of booleans should be handled in a particular way. openPersistentEditor() is a view method; the delegate methods do not get a pointer to the view. I cannot find view methods or signals that could be trapped to call the method. In the Icons Example, openPersistentEditor() is called when adding the data to a QTableWidget; I cannot do that as the data were already added long ago.
All of which leads me to believe that I am misunderstanding something fundamental, and I cannot see what it is. Hence the question.

Originally Posted by
jacek
As far as I understand, you want to influence the way your cell is displayed by opening a persistent editor, but this way you are just exploiting editing mechanism instead of fixing your delegate.
yes, that is how the Icons example in the documentation did it. I want the boolean column to appear as a column of checkboxes, and also to be edited as such. The QCheckBox knows how to draw that correctly. I don't, of course: it depends on whether the program is compiled on Linux, Windows or the Mac, what style is in operation, etc. So I don't see how I could override the paint method, like in the Star Delegate example, and draw my own checkbox, when I don't know what it should look like.

Originally Posted by
jacek
In case of checkboxes the easiest way is to set the Qt::ItemIsUserCheckable flag in your model.
If that works, it would be brilliant! Should this work with the standard delegate? I got rid of my delegate and put ItemIsUserCheckable in the model:
Qt
::ItemFlags CProcTableModel
::flags(const QModelIndex &index
) const{
Qt::ItemFlags result = Qt::ItemIsEnabled;
if (index.isValid())
if (index.column() == ixSelected)
result |= Qt::ItemIsUserCheckable;
return result;
}
Qt::ItemFlags CProcTableModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags result = Qt::ItemIsEnabled;
if (index.isValid())
result = QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
if (index.column() == ixSelected)
result |= Qt::ItemIsUserCheckable;
return result;
}
To copy to clipboard, switch view to plain text mode
The model's data() method uses
return QVariant((bool)m_Selected[ix]);
To copy to clipboard, switch view to plain text mode
for both Qt:: DisplayRole and Qt::EditRole on any cell in that column. It doesn't make any difference; the cells are still displayed as "true" or "false" and edited with a combobox with values "True" and "False" (with the different capitalisation; curious but not important).
What obvious thing have I missed?
Thanks
Frank
Bookmarks