[Kde-games-devel] Co-ordinates in QGraphicsView

Ian Wadham iandw.au at gmail.com
Sun Jul 1 01:06:05 UTC 2012


Hi guys,

When looking at how to port KGoldrunner to QGraphicsView, I have struck some
design problems and am looking for some help.

In the QGraphicsView module, a scene (QGraphicsScene) and a view (QGraphicsView)
each have their own co-ordinate system and there is an automatic transformation
between them.  This works fine for simple items like lines, rectangles, circles and
ellipses, but how does it work for pixmaps rendered from SVG by KGameRenderer?

Suppose I have a 10x10 grid full of pixmaps in a scene.  It would be nice if I could
use scene co-ordinates X = 0 to 9 and Y = 0 to 9 and the view would work out
however many pixels that comes to, e.g. the view is 400x400 pixels, so each
grid square is painted as 40x40 pixels.  That works fine if there is a
QGraphicsRectItem in each square.

So I find out what size the QGraphicsView is in pixels (e.g. 400x400) and I
divide by 10 to get the grid-square size and ask KGameRenderer to provide
me a pixmap item (actually KGameRenderedItem) of the right size (i.e. 40x40),
but now the pixmap gets scaled up when it is painted on the view and it is
horribly pixellated.

I guess the scaling of QGraphicsPixmapItem is OK for photos, etc., but how
do you use it with pixmaps pre-rendered to a certain size?

It seems to me that I have to use the same pixel-based co-ordinates in both
the QGraphicsScene and the QGraphicsView and change all the scene item
co-ordinates and sizes after every resize of the QGraphicsView (not to mention
the size of the whole scene), so that the scale factor for rendered pixmaps is
always 1.0.

Or am I missing something?

I am asking because it would be nice if I could use the same co-ordinate
system in both the game engine (model) and the QGraphicsScene.

Cheers, Ian W.



More information about the kde-games-devel mailing list