Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
4.6.3
-
None
Description
When using QGraphicsTextItem or QGraphicsSimpleTextItem to draw text that uses a QBrush containing a gradient, if the painters Pen style is set to Qt::NoPen, the gradient will not be drawn. This is normal for a QTextLayout itself, but when QGraphicsTextItem or QGraphicsSimpleTextItem uses QTextLayout, a QTextCharFormat is set enabling a text outline. Now instead of the pen specifying the brush color, the pen specifies the outline color and the brush specifies the text color.
This problem occurs because of the logic in QTextLine::draw (qtextlayout.cpp:2252) in Qt 4.6.3
When a QTextLine has a QTextCharFormat::penProperty of QTextFormat::TextOutline who's style is not Qt::NoPen (QGraphicsTextItems do), then the text is converted to a QPainterPath and where the outline is painted with the pen color, and then filled with the Brush. If the penProperties style is set to Qt::NoPen however then drawText is used instead.
The following code demonstrates this bug:
#include <QtGui> #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); QLinearGradient linearGrad(QPointF(0, 0), QPointF(1., 1.)); linearGrad.setColorAt(0, Qt::red); linearGrad.setColorAt(1, Qt::blue); QGradient grad=linearGrad; grad.setCoordinateMode( QGradient::ObjectBoundingMode ); QBrush brush ( grad ); QPen pen(Qt::black); pen.setWidthF(0.0); pen.setStyle( Qt::NoPen ); QGraphicsSimpleTextItem item; item.setPen(pen); item.setBrush(brush); QFont f = qApp->font(); f.setPointSizeF(40); f.setPointSize(40); f.setFamily("Sans"); item.setFont(f); item.setText("This is a test String"); const QRectF brect = item.boundingRect(); QStyleOptionGraphicsItem opt; opt.state = QStyle::State_None; //Create and paint bad image QImage bimg((int)brect.width(), (int)brect.height(), QImage::Format_ARGB32_Premultiplied); QPainter p2; p2.begin( &bimg ); p2.setCompositionMode( QPainter::CompositionMode_Clear); p2.fillRect(brect, QBrush( QColor( 0, 0, 0, 255))); p2.setCompositionMode( QPainter::CompositionMode_Source ); item.paint(&p2, &opt, 0); p2.end(); item.setPos( 0, 100 ); bimg.save("imagebad.png"); //Create and paint good image pen.setWidthF(0.0); pen.setStyle( Qt::SolidLine ); item.setPen(pen); QImage gimg((int)brect.width(), (int)brect.height(), QImage::Format_ARGB32_Premultiplied); QPainter p3; p3.begin( &gimg ); p3.setCompositionMode( QPainter::CompositionMode_Clear); p3.fillRect(brect, QBrush( QColor( 0, 0, 0, 255))); p3.setCompositionMode( QPainter::CompositionMode_Source ); item.paint(&p3, &opt, 0); p3.end(); item.setPos( 0, 100 ); gimg.save("imagegood.png"); return 0; }
Attachments
Issue Links
- relates to
-
QTBUG-12263 QPrinter: rendered composition contains blacked out background when the painter is rendered onto a printer
- Closed