Qt World Summit: Register Today!

Strange problem with qpixmap printing in debug and release mode

  • Hi all,

    I am working on a project that is developed in visual studio 2017. I am having some strange issues with printing of qpixmap header. This is the code that I use to generate header for my print job.

    //Construct header pixmap
    	headerPixmap = new QPixmap(pageSize.width(), headerHeight);
    	QPainter *headerPainter = new QPainter(headerPixmap);
    	headerPainter->setPen(*(new QColor(Qt::black)));
    	headerPainter->drawRect(0, 0, headerPixmap->width() - 1, headerPixmap->height() - 1);
    	QFont font = headerPainter->font();
    	QString headerText = printWidget->getPatient() + "     " + printWidget->getRecorded() + "  "+ printWidget->getPrinted() + "      " + printWidget->getSpeed();
    	headerPainter->drawText(20, 18, headerText);

    When I print a document in debug mode everything looks fine, but when I print document in release mode my header is totally darkened. These are the printed documents.


    Does anyone has any idea if I am missing something in release mode?

  • Lifetime Qt Champion

    When you say Release mode, do you mean when you run it standalone or do you
    still run it in Creator ?

    headerPainter->setPen(*(new QColor(Qt::black)));
    is not good.
    No reason to new it
    headerPainter->setPen( QPen(Qt::black) );

  • I figured it out.
    I just hat to explicit set brush on qpainter and everything works.

Log in to reply