Forbid selection of the column of view(model/view )
-
When I show the QDirModel by QTableView
There will be four columns -- Name, Size, Type, Date Modified
I don't want the user be able to select Size, Type, and Date Modified
How could I disable the selection on specific columns?The most easiest solution I could think of is design a delegate to
repaint the columns I don't want the user to select@
class disableSelectionDelegate : public QStyledItemDelegate
{
public:
explicit disableSelectionDelegate(QObject *parent = 0)
: QStyledItemDelegate(parent)
{
}void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->drawText(option.rect, Qt::AlignCenter, index.data().toString() ); }
};
@Thank you very much
-
Thanks, I didn't discover I could override the flag