Y.H.
Y.H.

Reputation: 2847

How to convert pixels to millimeters in Qt4.7?

I am working in a project where I am saving a drawing in .eps format.

The drawing itself is on a widget, I need to convert the size of the widget from pixels to millimeters so I can set the size of the output picture correctly.

This is the code I am using:

int widthmm  = QApplication::desktop()->widthMM();
int heightmm = QApplication::desktop()->heightMM();
int widthpx  = QApplication::desktop()->width();
int heightpx = QApplication::desktop()->height();
QSize epsPictureSize;
epsPictureSize.setWidth((picture.width*widthmm)/widthpx);
epsPictureSize.setHeight((picture.height*heightmm)/heightpx);
epsPrinter.setPaperSize(epsPictureSize,QPrinter::Millimeter);

The problem is that widthMM and heightMM are not reliable and give false results.

I need a cross-platform solution to get the physical measurements correctly.

Upvotes: 2

Views: 2912

Answers (1)

user297171
user297171

Reputation:

Those functions ask window management system, that is usually unsure itself. If you just want cute GUI, learn to use layout managers. If you have to display something of absolute size on screen (I had) you should do calibration. Display a line and let user resize it until it is exactly, say, 5cm.

Upvotes: 1

Related Questions