PDA

View Full Version : PyQt Filling in Table View cells



degan144
25th September 2015, 05:27
I'm struggling with filling in the cells of a Table View using a QStyledItemDelegate. I cannot figure out how to get the position of each cell so that I can fill certain cells with a color. I have attached a screenshot if that helps. Sorry if I am vague feel free to shoot me questions so I can clarify.

anda_skoa
25th September 2015, 11:08
Each cell is accessed via row/column information wrapped in a QModelIndex from the model that holds the data.
The model can easily provide background color information which should then be used by the delegate already.

If you need more than one color per cell, then you can still have the model provide the additional colors via custom roles and then use these roles in your delegate to query the colors using the QModelIndex's data() function.

If you must decide the color in the delegate for some reason, then look at the row/column information of the QModelIndex.

Cheers,
_