How to force repainting of QTableWidget?
it seems that QTableWidget skips repaint event if model data is not changed. But I use QItemDelegate and when its state is modified I want QTableWidget to be repainted. Methods update() and repaint() don't cause repaint. Any ideas how to force repaint?
What do you mean by "when its state is modified" ?
Nothing special :) For example, QPen used in MyItemDelegate is changed.
Did you try replacing the delegate with a new one with updated properties ?
You could of course simply tickle the model to emit the dataChanged signal. If you control the model, that's easy, but otherwise you can still do it. Are you using Qt 4 or 5?
[quote author="SGaist" date="1380534014"]Did you try replacing the delegate with a new one with updated properties ?[/quote]
I will try, but may be there is another solution...
[quote author="Andre" date="1380534699"]You could of course simply tickle the model to emit the dataChanged signal. If you control the model, that's easy, but otherwise you can still do it. Are you using Qt 4 or 5? [/quote]
I use Qt 4. How can I emit dataChange signal?
If you use your own model, then simply add a method that emits this signal for the complete range of indices in your table. If you are using a model you'd rather not subclass, you can either use a proxy model or a hack to emit the signal. While in Qt 4 signals are protected methods (in Qt 5 they are public, that's why I asked) you cannot just call the method directly. Instead, you can abuse QMetaObject::invokeMethod to call the method.
You will need a pointer to the model for this to work. Normally, a delegate doesn't have this. What I do in such cases, is make sure the parent of the delegate object can only be a QAbstractItemView*, and document you must use the view you are going to install the delegete on as the parent. Via the view, you can get the pointer to the model too.
So, you end up with something like this:
if (!m_parentView) return;
QAbstractItemModel* model = m_parentView->model();
if (!model) return;
QModelIndex topLeft = model->index(0,0);
QModelIndex bottomRight = model->index(model->rowCount()-1, model->columnCount()-1);
QMetaObject::invokeMethod(model, "dataChanged", Q_ARG(QModelIndex, topLeft), Q_ARG(QModelIndex, bottomRight));
Not pretty, but it should work. I did not test this myself though.