PDA

View Full Version : how costly i sthis??



tampstaffs
16th February 2009, 18:22
hi,

I have seen that in

void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget* /*widget*/);

{
painter->setClipRect(option->exposedRect);//update only the area which is visible currently

}

How costly is this?? is it resetting the region needed to be painted or is it clipping the qgraphicsitem itself??.Is it a better way to do this ,i just want to paint the part of item which is visible

wysota
16th February 2009, 22:16
How costly is clipping or drawing only on the clipped area? Clipping is in general expensive so if you don't really need it try to avoid it. The operation you pasted is similar to the "selection tool" you might know from painting application - it restricts all operations to the selected area. You can still perform them on any area you want but they will only have effect on the masked region.

fullmetalcoder
16th February 2009, 22:55
Mmmm... clipping by itself is not that expensive. What is expensive however is relying on it (and only it) to make sure no content is drawn out of given bounds. Clipping is a (very) suboptimal way to achieve that goal (because the whole drawing is performed but it is only "committed" in the areas marked as "writeable" by the clipping) and, as wysota mentioned though not very clearly IMO, it is way better to manually ensure that your rendering code does not draw anything out of bounds.

tampstaffs
17th February 2009, 03:09
Hi,

Can any one provide any example how i could achive this??

wysota
17th February 2009, 09:53
Mmmm... clipping by itself is not that expensive.
Depends if you clip to a rectangle or to a path/region.

fullmetalcoder
17th February 2009, 11:23
Depends if you clip to a rectangle or to a path/region
Sure but the example provided here clearly uses (or would use) rectangle clipping so this is not an issue.


Can any one provide any example how i could achive this??Depends what you mean by "this" ;)

By the way, it seems we still haven't clearly answered one of your original question :

setting a clip rect (or region or path) to a QPainter does not have any effect on the updating mecanism. It only affect the painting. When the paint event is called, the updating mecanism is already at its end (well not quite yet but the remaining path is out of your reach). Clipping at this point only affects the result of the painting operations in a very simple way : all operations requested will be performed but pixels will only be written to the screen if they are within the bounds allowed by the clipping.

To schedule repainting of a given region of an item you have to pass the coordinates of that region (must be a rectangle) to QGraphicsItem::update(QRectF& r) (http://doc.trolltech.com/latest/qgraphicsitem.html#update) method.