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. QTableView with custom model: color of disabled items
Forum Updated to NodeBB v4.3 + New Features

QTableView with custom model: color of disabled items

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 6 Posters 6.9k Views 4 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.
  • Christian EhrlicherC Christian Ehrlicher

    @StarterKit said in QTableView with custom model: color of disabled items:

    Any ideas?

    Use a delegate or a QIdentityProxyModel.

    S Offline
    S Offline
    StarterKit
    wrote on last edited by
    #21

    @Christian-Ehrlicher pardon, but I don't understand how QIdentityProxyModel can help for my case. From what I I read I see it returns the same values from data() method as any other model.

    With regards to delegates - I already commented.

    Christian EhrlicherC JonBJ 2 Replies Last reply
    0
    • S StarterKit

      @Christian-Ehrlicher pardon, but I don't understand how QIdentityProxyModel can help for my case. From what I I read I see it returns the same values from data() method as any other model.

      With regards to delegates - I already commented.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #22

      @StarterKit said in QTableView with custom model: color of disabled items:

      With regards to delegates - I already commented.

      But you want to fiddle around in QTableView? Wow...

      QIdentityProxyyModel

      This function class is there to allow to modify values returned from data() without affecting the base model. So tell this model the current widget state and return the right colors from there.

      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 StarterKit

        @Christian-Ehrlicher pardon, but I don't understand how QIdentityProxyModel can help for my case. From what I I read I see it returns the same values from data() method as any other model.

        With regards to delegates - I already commented.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #23

        @StarterKit
        I replied earlier stating the only two (reasonable) choices are a delegate or a proxy model.

        Since you do not wish to write a delegate, I suggested:

        If the OP really does not wish to create a delegate for the QTableView, an alternative is to create a QAbstractProxyModel local to the QTableView. Interpose that between the view and the original source model, and do the required data() alteration there (where it can access the view to see if it is disabled). At least then he is sure the model returning the "manipulated" value for the color is totally local to the individual view.

        So "do the required data() alteration there". A QIdentityProxyModel starts out "doing nothing" other than mapping straight through to the source model unchanged. You should derive from that to create your own sub-class. Then override and alter its data() method only (nothing else) to respond to the ForegroundRole by testing the view's "disablement" status and returning your desired color in that case. For all other cases in data() return the base QIdentityProxyModel's value.

        1 Reply Last reply
        3
        • S Offline
          S Offline
          StarterKit
          wrote on last edited by
          #24

          Ok, guys. Thank your for this discussion. I'll go and change my models...

          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