[Qt-interest] Update region granularity
Bob Hood
bhood2 at comcast.net
Mon Jun 13 00:40:30 CEST 2011
I have a QDialog with various child widgets. I am wanting to capture paint
updates to them, so I install an eventFilter for each widget in the QDialog
constructor, thus:
QList<QWidget *> widgets = findChildren<QWidget *>();
foreach(QWidget* widget, widgets)
widget->installEventFilter(this);
In the event filter, I trap paint events:
if(event->type() == QEvent::Paint)
{
QPaintEvent* paint_event = (QPaintEvent *)event;
if(paint_event)
...
And then I grab and cache the update by iterating over all the rectangles that
make up the region:
...
QWidget* widget = (QWidget*)object;
foreach(const QRect rect, paint_event->region().rects())
{
QPoint p = widget->mapTo(this, rect.topLeft());
QRect r = QRect(p, rect.size());
QString key = QString("%1x%2x%3x%4")
.arg(r.x())
.arg(r.y())
.arg(r.width())
.arg(r.height());
capture_list[key] = r;
}
...
This approach always seems to end up giving me a granularity that is no less
than the entire face of the widget. If it's a slider, for example, I end up
with rectangles derived from the QPaintEvent region() that represent the
entire slider, not just the portion of the slider that changed -- i.e., the
handle and the areas to the left and right of it.
My question: Is this the best granularity I can hope for by trapping updates
at the QDialog level (the "whole widget" granularity)? Can I only get
specific damage regions on individual widgets by sub-classing all of them and
re-implementing their (re)paint methods? This latter solution is really not
practical, because I really don't even know what the population of the QDialog
consists of, let alone know all their types and have to code sub-classes for
them all.
I can't go into a lot of detail about why I am doing this, but the goal is to
send the smallest amount of data over a network to refresh a GUI elsewhere.
If I'm stuck with the "whole widget" as the smallest amount, I suppose that
okay. I just want to make sure there's not something else I'm overlooking.
Thanks!
More information about the Qt-interest-old
mailing list