QTreeView won't change Foreground color on Windows
-
Hi everyone,
I have a strange behaviour on my Qt application and I can't understand what is going on.
I have written a Qt app with the aim to compile both Windows and Linux binaries.
In this app I have a QTreeView with a custom QAbstractItemModel. In this model I want the text displayed in red when the associated amount is negative.
I wrote a UnitTest program to check the returned value of a call to model.data() with the ForegroundRole and it is returning a QColor(Qt::red) as expected.
In Linux it works (compiled on Linux Ubuntu 22.04 with Qt 6.2.4):
But when I run the app in Windows (compiled on Windows 11 with Qt 6.7.1) the text stay black:
Have anyone encountered this behaviour before ?
-
As laready written in other threads - wait for 6.7.3 or use the windowsvista style until then. The new windows11 style has still some issues.
-
In general, palettes don't work with native styles perfectly. The native styles use native OS functions to draw the elements and so it is up to the operating system if it respects the palette or not. The Fusion style is not native and I guess it does not have this problem. The only safe solution (even if I don't particularly like it) is to use style sheets and forget about the palette.