QTableView with custom model: color of disabled items
-
@StarterKit said in QTableView with custom model: color of disabled items:
Any ideas?
Use a delegate or a QIdentityProxyModel.
@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 fromdata()
method as any other model.With regards to delegates - I already commented.
-
@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 fromdata()
method as any other model.With regards to delegates - I already commented.
@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
functionclass 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. -
@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 fromdata()
method as any other model.With regards to delegates - I already commented.
@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 aQAbstractProxyModel
local to theQTableView
. Interpose that between the view and the original source model, and do the requireddata()
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". AQIdentityProxyModel
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 itsdata()
method only (nothing else) to respond to theForegroundRole
by testing the view's "disablement" status and returning your desired color in that case. For all other cases indata()
return the baseQIdentityProxyModel
's value. -
Ok, guys. Thank your for this discussion. I'll go and change my models...