<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QTableView formatting depends on app style]]></title><description><![CDATA[<p dir="auto">Hi!<br />
I have an issue with this simple code:</p>
<pre><code>import sys
from datetime import datetime

from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtCore import Qt

class TableModel(QtCore.QAbstractTableModel):
    def __init__(self, data):
        super().__init__()
        self._data = data

    def data(self, index, role):
        if role == Qt.ItemDataRole.ForegroundRole:
            value = self._data[index.row()][index.column()]

            if (
                isinstance(value, int) or isinstance(value, float)
            ) and value &lt; 0:
                return QtGui.QColor("red")

        if role == Qt.ItemDataRole.DisplayRole:
            value = self._data[index.row()][index.column()]

            if isinstance(value, datetime):
                return value.strftime("%Y-%m-%d")

            return value

    def rowCount(self, index):
        return len(self._data)

    def columnCount(self, index):
        return len(self._data[0])

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()

        self.table = QtWidgets.QTableView()

        data = [
            [4, 9, 2],
            [1, -1, "hello"],
            [3.023, 5, -5],
            [3, 3, datetime(2017, 10, 1)],
            [7.555, 8, 9],
        ]

        self.model = TableModel(data)
        self.table.setModel(self.model)

        self.setCentralWidget(self.table)
        self.setGeometry(600, 100, 400, 200)

app = QtWidgets.QApplication(sys.argv)
# app.setStyle("Fusion")
window = MainWindow()
window.show()
app.exec()
</code></pre>
<p dir="auto">It formats the QTableView somehow. But it doesn't do it with the foreground color. For the default application style, it seems to just ignore the foreground formatting (Figure 1).<br />
<img src="https://ddgobkiprc33d.cloudfront.net/913ad214-cfa2-4a5f-9ac0-23cd05d7adab.png" alt="1.png" class=" img-fluid img-markdown" /><br />
Fig.1<br />
For the fusion style, things are better. (Just uncomment app.setStyle("Fusion"), Figure 2):<br />
<img src="https://ddgobkiprc33d.cloudfront.net/3c4b87b2-3b85-4132-8ac4-e73def58a673.png" alt="2.png" class=" img-fluid img-markdown" /><br />
Fig.2</p>
<p dir="auto">This code worked fine until recently but from some point it broke.<br />
Any ideas what might have gone wrong?</p>
<p dir="auto">Package   Version</p>
<hr />
<p dir="auto">pip       24.2<br />
PyQt6     6.7.1<br />
PyQt6-Qt6 6.7.2<br />
PyQt6_sip 13.8.0</p>
<p dir="auto">Processor	11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz   3.00 GHz<br />
Installed RAM	8,00 GB (7,75 GB usable)<br />
System type	64-bit operating system, x64-based processor</p>
<p dir="auto">Edition	Windows 11 Pro<br />
Version	23H2<br />
OS build	22631.4037</p>
]]></description><link>https://forum.qt.io/topic/158296/qtableview-formatting-depends-on-app-style</link><generator>RSS for Node</generator><lastBuildDate>Mon, 15 Jun 2026 07:21:28 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/158296.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Aug 2024 16:06:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QTableView formatting depends on app style on Tue, 20 Aug 2024 05:46:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> said in <a href="/post/807628">QTableView formatting depends on app style</a>:</p>
<blockquote>
<p dir="auto">Hi,</p>
<p dir="auto">There's a new style for Windows11 that seems to have some issue. You can also try the <code>windowsvista</code> style.</p>
</blockquote>
<p dir="auto">Yes, you're right, thanks.<br />
I kept looking for and found that: [<a href="https://bugreports.qt.io/browse/QTBUG-126543" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/browse/QTBUG-126543</a>](link url) so it is definetely a bug.</p>
]]></description><link>https://forum.qt.io/post/807653</link><guid isPermaLink="true">https://forum.qt.io/post/807653</guid><dc:creator><![CDATA[George55978]]></dc:creator><pubDate>Tue, 20 Aug 2024 05:46:52 GMT</pubDate></item><item><title><![CDATA[Reply to QTableView formatting depends on app style on Mon, 19 Aug 2024 18:37:29 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">There's a new style for Windows11 that seems to have some issue. You can also try the <code>windowsvista</code> style.</p>
]]></description><link>https://forum.qt.io/post/807628</link><guid isPermaLink="true">https://forum.qt.io/post/807628</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 19 Aug 2024 18:37:29 GMT</pubDate></item></channel></rss>