QGraphicsView itself has no facilities for this but you can implement a veeeeery simple function to map between units.
Units and coordinates are related strictly to the scene.And also I'm interested in a most effective approach to implementing this mapping from the QGraphics class hierarhy point of view - on which level (view, scene or item) it is recommended to do?
Yes.Currently for testing purposes I've just called logicalDpiX() and logicalDpiY() methods of my view and found scale factor for graphical objects (25.4/dpi_x and 25.4/dpi_y - this values can be different, right?
Yes this is true, provided you don't set a size of the scene. If you do, one pixel of the view equals one unit in the scene as long as you don't do any scaling.And yes, I assume that initially - when there are no any scene transformations used - scene coords are equal to view coords. At least that's what I see using mapToScene/mapFromScene methods.
Eeem... what values?Then I'm passing this values to every constructor of every graphical object and use them in their paint methods.
I'm not sure what you mean but this shouldn't be the case. Once you have units set and you operate in these units, you don't have to do any math.This approach doesn't fully satisfy me due to a lot of manually performed math (scattered around my project), additional constructor parameters I have to pass to every object and because I don't know how to deal with printer resolutions in this approach.
Logical units are always square. Physical units may not be square if you provide different transformations in horizontal and vertical directions.but only in case there is a guaranty that the scene logical units are always square (have the same physical step in horizontal and vertical directions) regardless of the size
Bookmarks