This is not necessary in Qt, because update events are compressed and will not be delivered until the control returns to the event loop. For example, the following will result in only one redraw of the label:
void test(QLabel * label) {
label->setText("foo");
label->update();
label->setText("bar");
label->setText("baz");
}
If you are sure that your updates alternate with returns to the event loop, then you can implement freeze / thaw as follows by filtering update events. The following is in C ++, feel free to translate it into Python :)
class UpdateFilter : public QObject {
Q_OBJECT
QSet<QObject> m_deferredUpdates;
Q_SLOT void isDestroyed(QObject * obj) {
m_deferredUpdates.remove(obj);
}
Q_OBJECT bool eventFilter(QObject * obj, QEvent * ev) {
if (ev->type() == QEvent::UpdateRequest) {
if (! m_deferredUpdates.contains(obj) {
m_deferredUpdates.insert(obj);
connect(obj, SIGNAL(destroyed(QObject*)), SLOT(isDestroyed(QObject*)));
}
return true;
}
return false;
}
public:
void thaw(QWidget * w) {
if (m_deferredUpdates.contains(w)) {
w->update();
m_deferredUpdates.remove(w);
}
};
Q_GLOBAL_STATIC(UpdateFilter, updateFilter)
void freeze(QWidget * w) { w->installEventFilter(&updateFilter()); }
void thaw(QWidget * w) { updateFilter().thaw(w); }
source
share