Responsibility of cropping QPixmap in paintEvent
-
wrote on 31 Oct 2016, 19:39 last edited by
Hi,
If paintEvent() draws piece of pixmap which is i.e. 1000x1000 entire, but that painted chunk is i.e. just 200x200 in the bottom-right corner of painting area, who is responsible for cropping that pixmap?
Is this sufficient?:QPixmap pixmap(1000, 1000); painter.drawPixmap(painter.width() - 200, painter.height() - 200, pixmap);
or drawPixmap(sourceRect, pixmap, destinationRect) has to be used?
-
Hi,
If you only want to paint parts of your pixmap, then it's up to you to tell the painter what to paint from the original pixmap.
-
wrote on 31 Oct 2016, 21:33 last edited by
@SGaist Thank You.
I'm asking in a context:
when I directly crop a pixmap by defining source and destination rectangles, will it influence on effectiveness?
Or it is the same like calling drawPixmap with "entire" pixmap, because it will be cropped by Qt routines? I've done that already in many places but I'm wondering is it correct. -
Where's you pixmap coming from and how do you determine the part that you want to be painted ?
-
wrote on 1 Nov 2016, 21:40 last edited by SeeLook 11 Jan 2016, 21:41
The pixmap is static object - an image loaded from file during app launch time, then scaled according to geometry. Then widgets laying above, paint its part in their paintEvents.
/* ------------------------------------------ | | | | | widget 1 | | | | -------------------|............. | | pix|map | |........................................| | | widget | 2 | | ------------------------------------------ | |................................| */
-
Do you mean that you are painting parts of the pixmap on widget 1 and widget 2 ? How are these two widgets related ?
-
wrote on 1 Nov 2016, 22:14 last edited by SeeLook 11 Jan 2016, 22:17
-
If I understands things correctly, these two pieces of the pixmap won't really change. If so, it would likely make more sense to store the parts you need to paint and only paint that. That would avoid needles cropping operations.
-
wrote on 3 Nov 2016, 20:32 last edited by
In fact, it is the best solution.
If there will be already cropped pixmap that simpler call of drawPixmap() remains.Thanks for clue!
8/9