Customise border radius of QTableView row selection
-
wrote on 14 Sept 2021, 17:25 last edited by
I would like to customise the QTableView selection border, ie when I select a row in the table, the selection border should be a circular (the border-radius function).
-
I would like to customise the QTableView selection border, ie when I select a row in the table, the selection border should be a circular (the border-radius function).
@siya
subclassing QStyleItemDelegate should do what you want (untested though):void MyStyleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { bool isSelected = option.state & QStyle::State_Selected; QStyleOptionViewItem opt = option; opt.state &= ~QStyle::QStyle::State_Selected; QStyledItemDelegate::paint(painter, opt, index); if( isSelected ){ // draw rounded rect using painter } }
-
@siya
subclassing QStyleItemDelegate should do what you want (untested though):void MyStyleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { bool isSelected = option.state & QStyle::State_Selected; QStyleOptionViewItem opt = option; opt.state &= ~QStyle::QStyle::State_Selected; QStyledItemDelegate::paint(painter, opt, index); if( isSelected ){ // draw rounded rect using painter } }
wrote on 14 Sept 2021, 21:14 last edited by JoeCFD@raven-worx He wants to do this for the whole row, not for one item. I think this may be the last thing for him to do in his project.
-
@raven-worx He wants to do this for the whole row, not for one item. I think this may be the last thing for him to do in his project.
@JoeCFD
still possible (and the only way i think).
It needs to be checked if its a middle index or an index on the side of the view and draw the borders accordingly -
@JoeCFD
still possible (and the only way i think).
It needs to be checked if its a middle index or an index on the side of the view and draw the borders accordinglywrote on 15 Sept 2021, 13:50 last edited by@raven-worx Agree. That is the part missing in your previous code.
-
@raven-worx Agree. That is the part missing in your previous code.
wrote on 16 Sept 2021, 08:32 last edited by@JoeCFD @raven-worx Yes that is what I would like. I suppose the onus is on me to read up on the paint function and how to paint borders depending on which index is selected?
-
Hi,
You have the model index, so if it's the left most one, draw the left round corners and if it's the right most one, draw the right rounded corner.
The other option is to use one delegate for the first and last column to do the special painting. Note that this is not the correct solution if your users can reorder the columns.
7/7