I've subclassed a QStyledItemDelegate with the goal to draw a pixmap in the centre of a QTableView’s cell. Our pixmap does get rendered correctly but we lose all style defined in the stylesheet. Removing the delegate restores the style.

I would like to understand how to use a QStyledItemDelegate while maintaining the existing style. Here’s a PySide delegate that I thought would simply render the cell as is. Applying this delegate removes the style.

Qt Code:
  1. class MyStyleDelegate(QtGui.QStyledItemDelegate):
  2. def __init__(self, parent=None):
  3. super(MyStyleDelegate, self).__init__(parent)
  4.  
  5. def paint(self, painter, option, index):
  6. super(MyStyleDelegate, self).paint(painter, option, index)
  7.  
  8. modelIndex = index
  9. model = index.model()
  10. if isinstance(model, QtGui.QAbstractProxyModel):
  11. modelIndex = model.mapToSource(index)
  12.  
  13. options = QtGui.QStyleOptionViewItemV4(option)
  14. self.initStyleOption(options, index)
  15. style = options.widget.style() if options.widget else QtGui.QApplication.style()
  16. style.drawControl(style.CE_ItemViewItem, options, painter, options.widget)
  17. QtGui.QStyledItemDelegate.paint(self, painter, option, modelIndex)
To copy to clipboard, switch view to plain text mode 

When I step through this code, our widget is always None. That seems to contradict all the examples that I've found.

We're also differing from the examples and using a QTableView with a proxymodel but from what I've read that should not affect the style.

Any help would be welcomed.

(This has been cross-posted from a colleague's post on http://qt-project.org/forums/viewthread/37757/. We have yet to decide which is the best resource for our PySide questions.)