How do I convert a QStyleOptionViewItem into a QStyleOptionViewItemV4? Qt has the qstyleoption_cast() method, but no such method exists in PyQt4.<br><br>I have my own subclass of QStyledItemDelegate and have overridden the initStyleOption() method so that I can provide my own foreground/background colors, fonts, etc. The problem I'm running into is with the background color -- I need to set the backgroundBrush attribute, which is only available on QStyleOptionViewItemV4. So I need to somehow cast the QStyleOptionViewItem object into a QStyleOptionViewItemV4 object...<br>
<br>from PyQt4 import *<br><br>class MyItemDelegate(QStyledItemDelegate):<br><br> def initStyleOption(self, option, index):<br> QStyledItemDelegate.initStyleOption(self, option, index)<br><br> # set font family and color<br>
option.font.setFamily("Courier")<br> option.palette.setBrush(QPalette.Text, QtCore.Qt.red)<br><br> # set background color<br> # this doesn't work:<br> option.backgroundBrush = QBrush(QtCore.Qt.black)<br>
# neither does this:<br> option = QStyleOptionViewItemV4(option)<br> option.backgroundBrush = QBrush(QtCore.Qt.black)<br>