Greetings fellow Trolls,

I'm having some trouble understanding the QGraphics View Framework.
Or, to be more precise, how to use the Framework for a simple 2D Game I want to write.

In this yet unwritten game I would like to display a Sprite inside several rooms. The rooms all have the same size. Within a room there is always the player controlled sprite and some stuff, doors, pictures on the wall, some furniture.

In the KAsteroid example the Widgets size is set to 640,480 and the Screen coordinates to 0,0,640,440

That would be enough for me. I can position my Items in the Scene and I know where they will appear on the View. But this way seems to be rather limited. So I wonder is it possible to set some Scene coordinates and allow the Widget to be resized in a way that the Items will still fill the whole of it?

Taking the Asteroids example again, what would happen if I resized the widget, to 800x600 ?
Where would the Items go? I'd assume you'd have a 800x600 Widget with only 640x480 showing the game.

Can the Graphics View Framework be told to fill the Widget with the whole scene? So I can paint my Items in Scene coordinates and be sure that they will scale to fit the avaible space?

And how could that be done if I want to add networking support?
Can one player run the game in Fullscreen at 1280x1024 and some other in a 640x480 window and still allow mouse positions grabbed in one to correctly translate to the other?

I would be really nice if I could just go and tell my scene to be 0,0,100,100 or whatever, draw my items in that system and have it displayed on any widget size, be it full screen or windowed mode, local or remote.

Is there a way to do that? Or is it best to copy the ported Asteroids example?

As far as I can tell my screen->setSceneRect gets completly ignored.
I did a simply screen->setSceneRect(0,0,640,440)

I also captured Mouse Events like this
Qt Code:
  1. QString tmp;
  2. QPointF position = mouseEvent->scenePos();
  3. tmp += QString("Mouse here: %1, %2").arg(position.x()).arg(position.y());
  4. QGraphicsTextItem* test = this->addText(tmp);
  5.  
  6. test->setPos(position);
To copy to clipboard, switch view to plain text mode 


If my Widget (and therefore my View) is at 640x480 everything works as expected.
That is my mouse clicks appear where I clicked with coords from 0,0 to 640,440

If I do a resize, I can have mouse clicks way, way outside at -100,-150 or 700,900.

So, I hope I'm getting my question across. Kinda having trouble with them english words.


I'm really impressed with the forum so far and I hope you guys can help me.

Regards from Germany,
SkyRat