PDA

View Full Version : Unset Data by role



padma
17th February 2017, 06:19
Hello,

I currently set the background role for a cell in the following way. There is also string data in the cell that I have set using setItem.

model->setData(index, QColor(R,G,B),Qt::BackgroundRole);

Now I'm trying to 'unset' just the color I set to the model.
Is there a 'clear' to just clear the background role specified for the cell?

Thanks,
Padma

Ginsengelf
17th February 2017, 07:17
Hi, maybe set QColor() or QPalette::color(QPalette::Background)?

Ginsengelf

d_stranz
17th February 2017, 17:33
Now I'm trying to 'unset' just the color I set to the model.

When you call setData(), you are changing the model, so the only way to "unset" the model is to call setData() again with the default color. The model doesn't have any memory of its state before you made the change so it can't undo a change on its own.

If you don't know the default color, simply call data() with Qt:: BackgroundRole -before- you make any changes to the model. Save this color somewhere so you can use it to restore the original color. An easy way might be to call setData() with Qt:: UserRole and save it there if your model allows that.