PDA

View Full Version : Graphics View: Drawing Items that don't scale



Disperato
6th July 2009, 12:56
Hi everyone,

I need to find a way to draw Items such that they always get drawn in the same size, even when I zoom in on them.
For example, I want to be able to draw a Point like this:

drawMyPoint(position, thickness)

where 'position' should be in scene coordinates, whereas 'thickness' should be in pixels. The point shall be painted in the same size, independent from the zoom level.

The motivation for this is that I have to mark road crossings on a map. Until now I use 'drawPoint', but it only draws it as one coloured pixel.

Thanks for your help

Daniel

wysota
6th July 2009, 13:27
Read about QGraphicsItem::ItemIgnoresTransformations.

Disperato
6th July 2009, 13:51
Read about QGraphicsItem::ItemIgnoresTransformations.

I did, but as I understand I would still have to initially provide the size of the Item in scene coordinates, wouldn't I?

wysota
6th July 2009, 14:05
Yes, each item has to have a size... But this is easy if you do know the scene size.

Disperato
6th July 2009, 16:36
Yes, each item has to have a size... But this is easy if you do know the scene size.

I tried to do this with EllipseItems, but it didn't work well, and it is quite complicated. Actually I don't want the items to have a size. They should be just points without width and height. But I would like to be able to tell Qt to use a thicker pen.
Ultimately, Graphics View transforms the scene coordinates to view coordinates and draws a pixel somewhere on the screen. There should be no need to use a more complicated Item just to get a thicker point. :(

wysota
6th July 2009, 18:16
Actually I don't want the items to have a size.
Sure you do.


They should be just points without width and height.
A point is a mathematical concept, you can't visualize a point. What you want is something that occupies a pixel on the screen.

But I would like to be able to tell Qt to use a thicker pen.
So you want it to occupy a few pixels on the screen...


Ultimately, Graphics View transforms the scene coordinates to view coordinates and draws a pixel somewhere on the screen. There should be no need to use a more complicated Item just to get a thicker point. :(

The whole point of graphics view is that it operates in scene coordinates instead of screen coordinates. If you don't want scene coordinates, don't use graphics view or keep the scene resolution synchronized with the view resolution (which means "no zooming"). You can't eat a cake and have a cake.

All you need to do is to calculate how many units in world (scene) coordinates a single pixel on the screen occupies. This is an easy calculation if you know the size unit of the scene and the resolution of the view. You should know the former and Qt knows the latter - just use both pieces of information and you're done.