Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
4.5.2, 4.6.0
-
None
-
I am running the most up to date Snow Leopard, and I tested it with Qt 4.5.2 and Qt 4.6.0. This problem was confirmed by another user using Windows XP and the Qt 4.6 RC1.
-
22573ddffc28135fba2dbb9eb2d50a76cae0a09c
Description
When drawing text with a gradient, the gradient always uses logical coordinates. The example below should show a black to white gradient that spans from the left to the right of the text, but instead only shows the text as the ending color (white):
QLinearGradient gradient(0,0 ,0,1);
gradient.setColorAt(0, QColor(0, 0, 0));
gradient.setColorAt(1, QColor(255, 255, 255));
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
QPen pen(gradient, 4);
painter.setPen(pen);
painter.drawText(QRect(0,0,50,20), 0, "Hello World");
painter.end();
To get the intended effect, one has to use logical coordinates like so:
QLinearGradient gradient(0,0 ,0,50);
gradient.setColorAt(0, QColor(0, 0, 0));
gradient.setColorAt(1, QColor(255, 255, 255));
QPen pen(gradient, 4);
painter.setPen(pen);
painter.drawText(QRect(0,0,50,20), 0, "Hello World");
painter.end();
In fact, the setCoordinateMode method has no effect at all when drawing text. If you use logical coordinates but ObjectBoundingMode or DeviceBoundingMode you get the same effect as above:
QLinearGradient gradient(0,0 ,0,50);
gradient.setColorAt(0, QColor(0, 0, 0));
gradient.setColorAt(1, QColor(255, 255, 255));
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
QPen pen(gradient, 4);
painter.setPen(pen);
painter.drawText(QRect(0,0,50,20), 0, "Hello World");
painter.end();
Outputting the return from gradient.coordinateMode() after the setCoordinateMode shows the mode was set, it just has no effect.