Qt-interest Archive, August 2005
faster painting
Message 1 in thread
I've seen a lot of improvements by trying to add a little intelligence to my
paint., and in using Qt 4.0.1. As suggested from this forum I do my own
buffering. Below is a overview on how this is done. I show it here to see
if anyone in this group see's other ways to optimize my drawing code, and
maybe others can learn from it as well.
RoundButton *rb = new RoundButton();
rb->setAtribute(Qt::WA_PaintOnScreen);
// to nullify small flashes with movement of mouse
rb->setAtribute(Qt::WA_NoSystemBackground);
...
/********************************************/
RoundButton::resizeEvent(ResizeEvent *re)
{
QSize s = re->size();
int H = s.height();
int W = s.width();
int diameter,radius;
// pixmap is an internal variable of RoundButton
pixmap = Pixmap(s);
QPainter painter(&pixmap);
pixmap.fill(Qt::white);
int centerY = (int) (H/2);
int centerX = (int) (W/2);
if (W < H)
diameter = W;
else
diameter = H;
radius = (int) (diameter/2);
int xOffset = centerX - radius;
int yOffset = centerY - radius;
QRadialGradient gradient1(0,0,radius,cx,cy);
gradient.setColor(.1,color1);
gradient.setColor(.9,color2);
painter.setbrush(gradient1);
painter.drawElipse(xOffset,yOffset,diameter,diameter);
}
/***********************************************/
RoundButton::paintEvent(QPaintEvent *pe)
{
QPainter painter(this);
painter.drawPixmap(0,0,pixmap);
}
-------------------------------------------------------------------------------------------
Perhaps making all the variables as part of the class will save time in the
resizeEvent(variables such as gradient1,centerX, etc.)
Any advise on how to make this even faster most apreciated
-David
--
[ signature omitted ]
Message 2 in thread
On Thursday 18 August 2005 19:38, David Boosalis wrote:
> // to nullify small flashes with movement of mouse
> rb->setAtribute(Qt::WA_NoSystemBackground);
no system background is awful when you map a window on X11, or when you switch
virtual desktops. There's this brief moment where you can see through it,
which gives a very, well, un-solid impression.
You could keep the system background, and instead set your pixmap as
background brush on the widget's palette. Then leave the paint event empty.
Pro: extremely fast paint event, done in the server
Con: if you resize the widget, you will see tiling until the X-server has
delivered the configure notify event and you updated the pixmap.
Or you wait until Qt 4.1 and give us some time to experiment with a per-window
backing store. While it's common for programmer's to test drawing speed by
quickly moving one window on top of another window, it's very uncommon for
users. They hardly ever move windows, or resize them.
Matthias
Message 3 in thread
Matthias Ettrich wrote:
> On Thursday 18 August 2005 19:38, David Boosalis wrote:
> > // to nullify small flashes with movement of mouse
> > rb->setAtribute(Qt::WA_NoSystemBackground);
>
> no system background is awful when you map a window on X11,
> or when you switch virtual desktops. There's this brief
> moment where you can see through it, which gives a very,
> well, un-solid impression.
>
> You could keep the system background, and instead set your pixmap as
> background brush on the widget's palette. Then leave the
> paint event empty.
>
> Pro: extremely fast paint event, done in the server
I read this as 'setting a cache pixmap as background brush is
faster (at least not slower...) than dumping the cache in
the paint event'. Is this correct? On X11 and Win?
> Con: if you resize the widget, you will see tiling until the
> X-server has delivered the configure notify event and you
> updated the pixmap.
Would it be possible to have a list of such Do's and Don't's
somewhere in the painter docs?
Or maybe add some (more...) hints regarding performance
implications to the individual QWidget functions. Sometimes
it is hard to tell even when looking at the code (having
the source is certainly a huge advantage, but reading
through it takes more time then reading the docs...)
> Or you wait until Qt 4.1 and give us some time to experiment
> with a per-window backing store. While it's common for
> programmer's to test drawing speed by quickly moving one
> window on top of another window, it's very uncommon for
> users. They hardly ever move windows, or resize them.
Indeed.
Andre'
Message 4 in thread
André Pönitz wrote:
> Matthias Ettrich wrote:
> > ...
> Would it be possible to have a list of such Do's and Don't's
> somewhere in the painter docs?
I would like to see this whole discussion ("how to improve drawing
performance") wrapped up in one of the next Qt Quarterly issues :)))
E.g. there's been a good article way back about how to avoid flickering
when drawing text (e.g. in a splashscreen).
Cheers, Oliver