Change cursor for a particulat column in a QTableView?
I am using the Model/View Framework by using a QAbstractTableModel subclass and a QTableView.
I would like to make a particular column of the QTableView have a different UI because it is the only editable column in the whole table and I would like to highlight that to the user.
I am thinking of changing the cursor, but if there are other nicer methods then your suggestions are most welcome.
But for now how do I change the cursor for only a particular column?
I suggest you check with SelectionModel of view. Using this you will be able to set the color any cell to different color. You can use the setCurrentIndex of selection model to achieve some of these things. I will share you piece of code later
Key to this is in the data() method of your table model. The table view queries this for more than just the data (Qt::DisplayRole). In particular for every cell the view queries data() for the Qt::BackgroundRole and you can return a QBrush with a particular color depending on the column number.
I don't do C++ but in Python/PyQt5 it would be something like this:
@ def data(self, index, role) :
if role == Qt.BackgroundRole :
brush = QBrush(Qt.white)
if index.column() == EDITABLE_COLUMN_NUMBER:
...etc etc for other roles@