Qt-interest Archive, May 2007
Own rasterizing QPaintEngine for painting lots of rectangles
Message 1 in thread
Hi,
after asking about the fastest way to paint lots of rectangles in Qt, I had
to recognize that there is no satisfying solution within Qt. However I
implemented an algorithm based on a quadtree that allows painting 500000
rectangles within a fraction of a second. (Painting directly with Qt took
110 seconds). The idea is to paint the rectangles from back to front and
marking covered regions as filled in the quadtree.
Now I would like to support the whole range of graphic shapes. Not only
rectangles. Because there is only a very small number of non rectangles in
my pictures, I would like to use the Qt painting system for that. The whole
work of rasterizing the painting events is already done in Qt and I would
like to use it. The idea is to implement a QPaintEngine that only needs to
set and get the current color information for a pixel in my image. The
question is whether this is possible?
My first experiments show that just deriving from QPaintEngine and
implementing the drawPixmap() Method does not work. There is an infinite
recursion within QPaintEngine.
How can one get the painting operations that QPainter supports, such that
one only has to set/get the appropriate pixels?
Christoph
--
[ signature omitted ]
Message 2 in thread
Maybe I've got a solution for my problem. I could use
QPainter::CompositionMode_DestinationOver
Christoph
--
[ signature omitted ]
Message 3 in thread
Christoph Bartoschek wrote:
> after asking about the fastest way to paint lots of rectangles in Qt, I had
> to recognize that there is no satisfying solution within Qt. However I
> implemented an algorithm based on a quadtree that allows painting 500000
> rectangles within a fraction of a second. (Painting directly with Qt took
> 110 seconds). The idea is to paint the rectangles from back to front and
> marking covered regions as filled in the quadtree.
>
>
I may be coming into this thread way too late, but if you have your own
rectangle drawing code that draws to a raster I assume to tested this by
drawing directly to memory. I think you can use this code in conjunction
with QImage as long as you can use one of QImage's color models.
QImage has a constructor: QImage::QImage ( uchar * data, int width, int
height, Format format )
Where data is the raw memory output of the code you already wrote and
format is something like ARGB32.
So the process would be:
Draw to memory.
Create QImage pointing to your memory.
Create a QPixmap from QImage (This puts the image in graphics memory).
Keep the QPixmap around as a double buffer. (Turn the background off on
your widget)
delete QImage and Data.
Draw QPixmap to QWidget in paintEvent().
See the docs for more information. Just remember to delete that uchar*
data when you delete the QImage. Qt will not do that for you.
Good Luck,
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard