You are not logged in.

1

Friday, August 19th 2005, 12:16pm

Drawing in Qt4

Hi.

I am starting to build a card game in Qt4. What would be the best thing
to use to draw all the graphics? I was going to use QCanvas until
I saw that there is no QCanvas class in Qt4. Just QPainter, If I
use QPainter can I just draw things when I need to or do I need
to redraw everything if the window is obscured? If you get what
I mean.


Thanks.

2

Friday, August 19th 2005, 10:04pm

RE: Drawing in Qt4

First, I'm not an expert, YMMV. I think it depends on what you are doing. If you are constructing images off-screen and then copying them to your display device, or going directly to display device would change the answer. Have a look at these classes though, they're all related:
QImage
QPixmap
QPicture

Of these, QImage and QPixmap are more direct pixel drawing classes. QPicture is interesting, it replays painter commands...if you know what an OpenGL display list is, it's similar. A QPicture might be useful for a kind of scene graph.

To quote the manual data:
QPixmap is designed and optimized for drawing on screen; QImage is designed for I/O and for direct pixel access; QPicture provides a scalable, vectorial picture

So if you have a complex set of manipulations at the pixel level, you might go with QImage, and then copy the end result to a QPixmap. If you plan to render to the screen without a lot of data transfer, you might go for a QPixmap directly. If you have a series of repeatable geometries that need to be placed in a scene, you might use the QPicture. Combinations might also make sense.

I've found the non-OpenGL stuff though to be slow...if speed is required you might switch to the GL widget and render with OpenGL. For me the OpenGL is at least two to three orders of magnitude faster even in 2D, and I just have a cheap/low-end NVidia card (though admittedly even a low end NVidia is a fast video card).
-- "Quality is free", quoted from Dr. W. E. Deming

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

3

Friday, August 19th 2005, 10:38pm

You can use Q3Canvas. A replacement will be available in Qt 4.1

4

Saturday, August 20th 2005, 6:15am

RE: Drawing in Qt4

Im new to this, so bear with me. From what I can see by using Q3Canvas I dont get to take advantage of the new paint system. But from what I read it is quite efficent at painting (breaks the canvas up into blocks) and if I were to use a QPixmap with the new paint system I would have to repaint everything? Im looking at the KDE games source and they all seem to be using QCanvas. I wonder what will happen when they go to port them to Qt4? will they keep using Q3Canvas or will they find some alternative?

Thanks

dimitri

Professional

  • "dimitri" is male

Posts: 1,311

Occupation: Engineer

  • Send private message

5

Saturday, August 20th 2005, 8:28am

RE: Drawing in Qt4

I think all of Qt 4 uses the new paint system, including Qt3Support.