PDA

View Full Version : Draw text to QImage swaps red and blue colors



aftos
22nd May 2014, 07:45
Hi all,
I'm trying to render text into a qimage and then draw this image into a QGLWidget. Here's a piece of code:


int flags = Qt::AlignCenter;
QPainter tmpPainter;
QImage tmpImage(textRect.width(), textRect.height(), QImage::Format_ARGB32);

tmpImg.fill(Qt::transparent);
tmpPainter.begin(&tmpImg);
tmpPainter.setBrush(Qt::NoBrush);
tmpPainter.setPen(QColor(255, 0, 0));
tmpPainter.drawText(QRect(0, 0, tmpImg.width(), tmpImg.height()), flags, myText);
tmpPainter.end();

tmpImg = QGLWidget::convertToGLFormat(tmpImg);
tmpImg = tmpImg.mirrored();

glPainter->drawImage(textRect, tmpImg);


This draws the text blue instead of red! Why is that? The same goes if the color is (0, 0, 255) which gives me color red instead of blue.

I'm using Qt v4.8.4

ps: the format of the qimage was initially set to QImage::Format_ARGB32_premultiplied but i've seen the code of convertToGLFormat which converts the image to Format_ARGB32.