Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. pyqt5 qtreeview QAbstractItemModel set coloring of single column based on function?
Forum Updated to NodeBB v4.3 + New Features

pyqt5 qtreeview QAbstractItemModel set coloring of single column based on function?

Scheduled Pinned Locked Moved Solved Language Bindings
3 Posts 2 Posters 1.2k Views 2 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
    hermes
    wrote on last edited by
    #1

    I'm quite new to qtreeview (using python) and I'm searching for a way have the color (background and text color) of a colum (not the whole item) of a qtreeview.(using QAbstractItemModel) to be based on the return value of a given function. Whenever the value of the column changes, the coloring should be updated.

    Do I somehow have to connect to a changed-event and read things about delegates or proxymodels and I did not really understand it...

    Anyone got a hint? - Thanks a lot in advance

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      In the data method of your model, you can run whatever computation you need to determine the colour to return for the BackgroundRole.

      As for updating, that is done in the setData method when a value is changed, emit the dataChanged signal accordingly. This will trigger the views to update their content and thus read your model again.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hermes
        wrote on last edited by
        #3

        Great, I had missed that....
        I simply could not believe that it is actually that easy...

        Thanks a lot!

        1 Reply Last reply
        0

        • Login

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