Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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();
    	font.setPixelSize(12);
    	headerPainter->setFont(font);
    	QString headerText = printWidget->getPatient() + "     " + printWidget->getRecorded() + "  "+ printWidget->getPrinted() + "      " + printWidget->getSpeed();
    	headerPainter->drawText(20, 18, headerText);
    	//end
    

    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.

    0_1555067073627_7ecd7fe7-2050-4ff5-9178-a2b2bb7e34e6-image.png

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


  • Lifetime Qt Champion

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

    Also
    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.
    headerPainter->setBrush(Qt::lightGray);


Log in to reply