PDA

View Full Version : Custom Item Delegate Reset, sort of.



waynew
1st September 2010, 02:24
After you set a custom item delegate on a view row, how can you 'unset' it?
So the view row gets repainted according to say, the style sheet applied to it.

For example, if the style sheet colors the row brown and then the custom item delegate colors the row green, and your data changes so you want the row brown again, how do you do this?

Applying the custom item delegate works fine, but when the data changes and I need to re-color the row according to the style sheet, I don't see how to do it.

norobro
1st September 2010, 04:24
Just assign a new delegate to the row. For the default delegate use:

QAbstractItemView::setItemDelegateForRow(int, QAbstractItemView::delegate());
Don't know whether this will help or not, but I color cells in a view by testing in the paint method of a custom delegate. By using QModelIndex::sibling() you can color an entire row. Attached is an app that demonstrates this using the sqlite db "person" from the Qt examples. It colors rows with odd number ids. Try changing some of the ids.

wysota
1st September 2010, 10:24
You can always derive your custom delegate from QStyledItemDelegate and when you don't need the extra functionality, just disable it in your delegate and call the base class implementation.

waynew
1st September 2010, 22:48
Thanks for the help folks and the example Norobro. This is very cool. I would probably have never figured out you could do that.
Qt is really amazing.
Got the basics working fine, just need to do a little code cleanup and it's done.