Saturday 17 August 2013

QAbstractTableModel headerData background color role

QAbstractTableModel headerData background color role

I am trying to customize the header of my QTableView. The issue is that
Qt.DisplayRole works fine, but the Qt.BackgroundColor role fails to
render.
There are little clues on www but what I found is changing the application
style works. That is a hack is there a way to achieve it without the hack?
#------------------------------------
def headerData(self, section, orientation, role):
""" Header data """
if role == QtCore.Qt.DisplayRole:
if orientation == QtCore.Qt.Horizontal:
return self.dates[section]
elif orientation == QtCore.Qt.Vertical:
return "Name:"
elif role == QtCore.Qt.BackgroundRole:
if orientation == QtCore.Qt.Horizontal:
return QtGui.QColor(QtCore.Qt.red)
elif orientation == QtCore.Qt.Vertical:
return QtGui.QColor(QtCore.Qt.green)
-- app style
app.setStyle("Plastique")

No comments:

Post a Comment