Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeView won't change Foreground color on Windows
Forum Updated to NodeBB v4.3 + New Features

QTreeView won't change Foreground color on Windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 316 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harjel
    wrote on last edited by
    #1

    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):
    Linux.png

    But when I run the app in Windows (compiled on Windows 11 with Qt 6.7.1) the text stay black:
    Windows.png

    Have anyone encountered this behaviour before ?

    1 Reply Last reply
    0
    • kesterpmK Offline
      kesterpmK Offline
      kesterpm
      wrote on last edited by
      #2

      I am having a similar problem. I am porting my application to Qt 6.7. My code worked in Qt 5.15, but now it isn't showing the color like it is supposed to. I have not tried to compile the Linux version yet.

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonSchroeder
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved