Allthough the "scene units" can be declared as whatever you want, I found it most convenient to use "logical dots" because it facilates font handling most. So while my shapes are basically measured in mm, I need to calculate them to dots when creating a graphics item, but fonts are automatically drawn in theire optimal geometrics.
Dont mix the logical dots with the physical dots of screen and printer, physical dots should be only cared about at the level of the paint device (* and somewhat on the view), but not at level of the scene where everything is handled as logical dots which are allways square.
In your application you should take care about the facts that the size of logical dots are not a constant, but can vary for devices. For the screen on windows xp they are for example 96 DPI, while for a high resolution printer they might be 1200, 600 or 300 depending on the resolution selected in the print dialog.
(*) If you want the representation on the screen to be as exact as possible with real world units, you should do that in the zoom factor of the graphics view.
Here is an example how to find scale factors for exact screen zooming:
extern int qt_defaultDpi();
int screenLogicalResolution = qt_defaultDpi();
qreal dot2mm = 25.4 / qreal(screenLogicalResolution);
qreal mm2dot = qreal(screenLogicalResolution) / 25.4;
qreal hscale = qreal(desktop->width()) / qreal(desktop->widthMM()) * dot2mm;
qreal vscale = qreal(desktop->height()) / qreal(desktop->heightMM()) * dot2mm;
myGrapicsView->scale(hscale, vscale);
extern int qt_defaultDpi();
int screenLogicalResolution = qt_defaultDpi();
qreal dot2mm = 25.4 / qreal(screenLogicalResolution);
qreal mm2dot = qreal(screenLogicalResolution) / 25.4;
QDesktopWidget* desktop = QApplication::desktop();
qreal hscale = qreal(desktop->width()) / qreal(desktop->widthMM()) * dot2mm;
qreal vscale = qreal(desktop->height()) / qreal(desktop->heightMM()) * dot2mm;
myGrapicsView->scale(hscale, vscale);
To copy to clipboard, switch view to plain text mode
Bookmarks