Hi,
i want to paint a rectangle of 100mm x 100mm on a QPainter (or printer or what else).
Somehow the results on the screen differ on Windows, Linux and my Mac machine.
I wrote two transformation methodes:
One to transform mm to pixels for the width:
qreal
TestSite::widthInMM2Pixel(const qreal widthInMM)
{
return widthInMM / 25.4 * m_dpiX;
}
And analog for height:
qreal
TestSite::heightInMM2Pixel(const qreal heightInMM)
{
return heightInMM / 25.4 * m_dpiY;
}
The two methods
logicalDpiX()
and
logicalDpiY()
are from QPaintDevice and used as follows at initialisation:
m_dpiX = logicalDpiX();
m_dpiY = logicalDpiY();
Then painting like this:
void TestSite::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QBrush brush(Qt::blue);
painter.fillRect(0, 0, widthInMM2Pixel(100.0), heightInMM2Pixel(100.0), brush);
}
The result differs on each machine. Only some pixels but it’s not equal as expected.
Any ideas whats going on here?
Greetings
Nando
↧