Visual hint in table view that item is editable?
-
Certain cells in my table view are editable, but there's no visual hint in the way the information is displayed to tell the user that those cells are editable. What's the simplest clean/elegant way (assuming the use of the default QStyledItemDelegate) to provide this information to the user?
Unsetting flag Qt::ItemIsEnabled for the non-editable cells isn't appropriate for this case.
David
-
Hi,
You could highlight the background of your editable cells with a different color.
-
I was thinking of something similar to the light blue background shown here AFTER the cell has been edited ( I think it's a Gradient Brush). Strangely it's the same as all the other cells before it is edited???
How would I achieve something like that without writing my own Style sub-class.
Ideally using a Brush the Style would use rather than a single arbitrary solid colour or Gradient brush that I hard code. -
How do you know which cell can be edited and which not ?
-
QAbstractTableModel::flags()
inline Qt::ItemFlags flags(const QModelIndex& index) const override { auto flags = Inherited::flags(index); switch (Column(index.column())) { case Column::Path: flags |= (Qt::ItemIsUserCheckable); break; case Column::Type: case Column::ISO: case Column::Exposure: flags |= (Qt::ItemIsEditable); break; } return flags; }
-
You can return a custom value for the Qt::BackgroundRole.
-
I'm aware of that - what I want to do is to use a Brush for that comes from the current Style (e.g. Fusion), rather than creating my own.
I showed two examples earlier in the thread that would have done well which were clearly chosen by the Style when the cell was rendered - all I want to do is pick one of those up.
-
You can grab the QPalette from the style and get the color you want from it.