Details
-
Bug
-
Resolution: Done
-
P4: Low
-
4.7.2
-
None
-
OS X 10.6, Windows 7
Description
On OS X, but not on Windows or Linux, text drawn to a QImage is located approximately 1 pixel to the right of where it is when drawn directly to a window.
The attached image shows the effects on both OS X and Windows of the following code. The "ZoomIn" window on the left is an enlarged view of the two windows. The top "example" in each window is drawn directly on the window and the bottom "example" is drawn to a QImage which is then drawn on the window. A coloured line is drawn before the text to help perceive the difference and also to show that this is not caused by the QImage drawing to the wrong location on the window.
On Windows, the texts are aligned with the first ink of the initial 'e' occurring in the first pixel, horizontally. On OS X the texts are not aligned with the directly drawn text starting in the first pixel but the text drawn to the QImage starting on the second pixel.
Code:
void Ferry::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
QFont fontV("Verdana", 10);
painter.setFont(fontV);
QString sExample = "example";
QPointF ptV(0, 12);
painter.fillRect(1, 1, 1, 10, QColor("#8D8"));
painter.drawText(ptV, sExample);
QSize imageSize(100,18);
QImage pixI(imageSize, QImage::Format_RGB32);
QPainter painterI(&pixI);
painterI.setFont(fontV);
painterI.fillRect(0, 0, imageSize.width(), imageSize.height(), QColor("#FFF"));
painterI.fillRect(1, 1, 1, 10, QColor("#FBB"));
painterI.drawText(ptV, sExample);
QRect target(0, 18, imageSize.width(), imageSize.height());
QRect source(0, 0, imageSize.width(), imageSize.height());
painter.drawImage(target, pixI, source);
}