QTableView formatting depends on app style
-
Hi!
I have an issue with this simple 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 < 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()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).

Fig.1
For the fusion style, things are better. (Just uncomment app.setStyle("Fusion"), Figure 2):

Fig.2This code worked fine until recently but from some point it broke.
Any ideas what might have gone wrong?Package Version
pip 24.2
PyQt6 6.7.1
PyQt6-Qt6 6.7.2
PyQt6_sip 13.8.0Processor 11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz 3.00 GHz
Installed RAM 8,00 GB (7,75 GB usable)
System type 64-bit operating system, x64-based processorEdition Windows 11 Pro
Version 23H2
OS build 22631.4037 -
Hi,
There's a new style for Windows11 that seems to have some issue. You can also try the
windowsvistastyle. -
Hi,
There's a new style for Windows11 that seems to have some issue. You can also try the
windowsvistastyle.@SGaist said in QTableView formatting depends on app style:
Hi,
There's a new style for Windows11 that seems to have some issue. You can also try the
windowsvistastyle.Yes, you're right, thanks.
I kept looking for and found that: [https://bugreports.qt.io/browse/QTBUG-126543](link url) so it is definetely a bug.