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

Christian Krippendorf Coding at Christian-Krippendorf.de
Sun Jul 1 10:04:58 UTC 2012


On 01.07.2012 03:06, Ian Wadham wrote:
> 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.
>
> _______________________________________________
> kde-games-devel mailing list
> kde-games-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kde-games-devel
>

Hey,

maybe u also want to have a look on branches/work/krippendorf. On this 
port of KMahjongg i create my own GameItem derived from QGraphicsItem. 
It is also represented as a pixmap from svg items.

Maybe this could help you.

-- 
Mit freundlichen Grüßen / Best Regards

Christian Krippendorf



More information about the kde-games-devel mailing list