QTableView show better seleced/focused Row
Unsolved
General and Desktop
-
I have a QTableView and I must enable SingleSelection (Cell) for editing. So only the current cell gets a special background for selection.
In this case I cannot really good see what row is/was selected, especial when I leave the tableview or I have a simple ActionButton delegate in a column.Is it possible to get a selection coloring like MS-Office/Access-Tables:
The whole row gets a special background and the current selected cell an other background
-
- sublcass QStyledItemDelegate
- reimplement it's initStyleOption() method
- call the base class implementation first
- check the options state for selection and focus
void MyItemDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const { QStyledItemDelegate::initStyleOption(option, index); if( option->state & QStyle::State_Selected ) option->backgroundBrush = QBrush( Qt::red ); if( option->state & QStyle::State_HasFocus ) option->backgroundBrush = QBrush( Qt::yellow ); }