Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, January 2008
Working with QImage


Message 1 in thread

[newbie warning]

Hello! I am doing a program to show basic graphic systems algorythms.
To do that, I need to draw in a matrix-oriented way, as I need access
to every pixel. So, I decided to use a QImage.

The QImage is working like a viewport, so it can be resized and I have
to code all the transformation matrices and viewport convertions.

When I get to the point in which I had to redraw the scene, I couldn't
find a way to "clean" the QImage, so what I did was to create it as a
pointer, and every time I get into paintEvent I delete the old image
and create a new one (which also works pretty fine if the program is
resized, as the image is created using the correct width and height).

Of course, this may not be the fattest way to achive this. Is there a
more convenient way? (I could then delete the image and create a new
one only on a resizeEvent call) .

Any ideas would be appreciated. I would like to show you the source
code, but my server is down for a few more days :-(

Regards, Lisandro.


-- 
 [ signature omitted ] 

Message 2 in thread

On Wednesday 02 January 2008 04:54:23 am Lisandro DamiÃn Nicanor PÃrez Meyer 
wrote:
> Hello! I am doing a program to show basic graphic systems algorythms.
> To do that, I need to draw in a matrix-oriented way, as I need access
> to every pixel. So, I decided to use a QImage.
>
> The QImage is working like a viewport, so it can be resized and I have
> to code all the transformation matrices and viewport convertions.
>
> When I get to the point in which I had to redraw the scene, I couldn't
> find a way to "clean" the QImage, so what I did was to create it as a
> pointer, and every time I get into paintEvent I delete the old image
> and create a new one (which also works pretty fine if the program is
> resized, as the image is created using the correct width and height).
>
> Of course, this may not be the fattest way to achive this. Is there a
> more convenient way? (I could then delete the image and create a new
> one only on a resizeEvent call) .
You could try using the QGraphicsView/QGraphicsScene stuff. That should still 
give you the degree of control you need, and will automagically handle 
resizing / changing the view of the area.

Brad


--
 [ signature omitted ] 

Message 3 in thread

In paintEvent()
Use  this code snippet.

	QPainter painter(pImage)
	painter.setCompositionMode(QPainter::CompositionMode_Source)
	painter.fillRect(0,0,pImage->width(),pImage->height(), Qt::transparent);

This code clear the contents of the pImage to transparent.

Samuel B. Park

-----Original Message-----
From: Brad Hards [mailto:bradh@xxxxxxxxxxxxx] 
Sent: Tuesday, January 01, 2008 2:46 PM
To: qt-interest@xxxxxxxxxxxxx
Cc: Lisandro DamiÃn Nicanor PÃrez Meyer
Subject: Re: Working with QImage

On Wednesday 02 January 2008 04:54:23 am Lisandro DamiÃn Nicanor PÃrez Meyer 
wrote:
> Hello! I am doing a program to show basic graphic systems algorythms.
> To do that, I need to draw in a matrix-oriented way, as I need access
> to every pixel. So, I decided to use a QImage.
>
> The QImage is working like a viewport, so it can be resized and I have
> to code all the transformation matrices and viewport convertions.
>
> When I get to the point in which I had to redraw the scene, I couldn't
> find a way to "clean" the QImage, so what I did was to create it as a
> pointer, and every time I get into paintEvent I delete the old image
> and create a new one (which also works pretty fine if the program is
> resized, as the image is created using the correct width and height).
>
> Of course, this may not be the fattest way to achive this. Is there a
> more convenient way? (I could then delete the image and create a new
> one only on a resizeEvent call) .
You could try using the QGraphicsView/QGraphicsScene stuff. That should still 
give you the degree of control you need, and will automagically handle 
resizing / changing the view of the area.

Brad


--
 [ signature omitted ]