[Interest] Customize QTableView selection color

Murphy, Sean smurphy at walbro.com
Fri Feb 5 16:34:19 CET 2016


I’m still struggling with how to customize the selection color for items on a QTableView (previously posted as http://lists.qt-project.org/pipermail/interest/2016-January/020760.html). I currently color the rows with custom colors based on the data being shown in each row in my model’s data(const QModelIndex &currIndex, int role) when role == Qt::BackgroundRole.

I’d like for that color to persist when the user selects a row; so either I want the selection to only paint the dotted line around the entire row without changing the background color to the OS’s default selection color, or I’d also be fine if there was no change at all  when the row is selected. The only reason I allow rows to be selected at all is apparently that is required to allow the user to start a drag on a row when they are attempting to reorder the rows in the table. I can’t seem to figure out where this needs to happen.

Correct me if I’m wrong on any of the following:

1.       I can’t use a stylesheet because the colors are different on a row-by-row basis

2.       I don’t think the selection background color is controlled anywhere in the model?

3.       I really don’t have any need for the user to be able to select anything – the table is meant to be a read-only display of data - EXCEPT it appears that being able to select items is a requirement for the drag-n-drop system?

Any pointers?
Sean






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160205/a2dfc84d/attachment.html>


More information about the Interest mailing list