Well QItemDelegate::drawBackground() is pointless as there is a bug in Qt-this function has been forgotten to be declared as virtual :/
About your code,I'd write it like:
Qt Code:
  1. if(role == Qt::BackgroundRole && index.isValid())
To copy to clipboard, switch view to plain text mode 
but even without this 'purism' it seems to be OK.For the test,screw up the gradient and return a simple QColor to see if it works.