I have successfully used the following Qt code in my python application to color horizontal headers in a QTableWidget with distinct background colors:
header2 = widget.horizontalHeaderItem(2)
purple = QColor(139,103,153)
header2.setBackground(QtGui.QBrush(purple))
header3 = widget.horizontalHeaderItem(3)
orange = QColor(237,168,89)
header3.setBackground(QtGui.QBrush(orange))
However, in my C++ Qt plugin for an existing application, the equivalent logic does not work for the QTableWidget horizontal headers, but does work for table cells or QTableWidgetItem.
The C++ application has it's own style with a dark theme. If I replace the style with plastique, then my code works.
QApplication::setStyle("plastique");
However, this is not an acceptable solution, as it changes the appearance of the entire application.
I have searched the web and stackoverflow for a solution and this post seems relevant. It appears to be subclassing QHeaderView, but the implementation is a little advanced for me. Unfortunately, the post above does not solve work in my case.
Am I on the right track? Can someone provide a little more detail about the .h and .cpp and main() implementation?