PDA

View Full Version : View with custom delegate not reacting to update() an repaint()



SK
13th July 2006, 20:08
Hello again,
my problem is the following: I have a custom sql table model inheriting from QSortFilterProxyModel and a view with a custom delegate onto this. The custom delegate colors certain elements in the table differently (to be exact, new table entries get colored red for 40 seconds). The problem is that the view won´t update using update() or repaint().
So when a new entry is added to the sql table, it shows up in my model. After it shows up there it is detected and the row is marked as "special" for the delegate. Now I call update() with the intention that the view will color the row red as expected ... but it doesn´t, basically nothing happens.
OTOH, if I force a resize call by resizing the window, or if i do another update of the underlying model, triggering an automatic update of the view, everything works as expected. It of course would look a bit dumb to let screen resize everytime I need an update ;) .Is there anything special to consider when using custom delegates? I already checked multiple times that I haven´t accidently disabled updates or stuff like that.

jpn
13th July 2006, 21:10
You have several options to make the view update accordingly.

Inform the change though the model:
- void QAbstractItemModel::dataChanged (http://doc.trolltech.com/4.1/qabstractitemmodel.html#dataChanged)(const QModelIndex& topLeft, const QModelIndex& bottomRight) [signal]
- void QAbstractItemModel::reset (http://doc.trolltech.com/4.1/qabstractitemmodel.html#reset)() [protected]

Or you can either make the view update itself by calling:
- void QAbstractItemView::setDirtyRegion (http://doc.trolltech.com/4.1/qabstractitemview.html#setDirtyRegion)(const QRegion& region) [protected]
- void QAbstractItemView::reset (http://doc.trolltech.com/4.1/qabstractitemview.html#reset)() (this makes the whole view updated i think)

There might be even more ways to do that. Calling just update() or repaint() won't do the trick since the view doesn't know that the model has changed in any way.