Color individual horizontal headers of QTableWidget in PyQt
<p>I have a QTableWidget where I would like to color individual horizontal header items based on some criterion.</p>

<p>What I have come up with so far: </p>

<pre><code>stylesheet = "::section{Background-color:rgb(190,1,1)}"
self.ui.Table.horizontalHeader().setStyleSheet(stylesheet)
</code></pre>

<p>This works, however it colors all headers simultaneously without me being able to change the color of an individual header. So the next logical step would be:</p>

<pre><code>self.ui.Table.horizontalHeaderItem(0).setStyleSheet(stylesheet) 
</code></pre>

<p>This does not work, as a single header item does not support setting a stylesheet.</p>

<p>Finally:</p>

<pre><code>self.ui.Table.horizontalHeaderItem(0).setBackgroundColor(QtCore.Qt.red)
</code></pre>

<p>This runs just fine without python complaining, however it does not seem to have any effect on the background color whatsoever.</p>

<p>I already looked at <a href="https://stackoverflow.com/questions/19198634/pyqt-qtablewidget-horizontalheaderlabel-stylesheet">this answer</a>, it is what sparked my first attempt. However it only deals with coloring all headers with the same color.</p>

<p><strong>How can I color the headers individually?</strong> </p>