Qt Problem with kerning in the text when using QPrinter/ QPainter to a .pdf
-
This is probably an easy fix but I have been trying to figure it out for over a month. My goal is to write a report straight to a .pdf file which works but I can't get the text that I am adding to a DrawRect to Kern.
Example:
@// creates a report for a single account or a group of accounts based on the billing month with a price sheet
bool ReportOptions::generatePdf(QString &fileName, bool priceSheet)
{
if (fileName.length() == 0)
return false;
if (!fileName.contains(".pdf", Qt::CaseSensitive))
fileName.append(".pdf");int counter = 0; bool finished = false; if(pAccForm->getMassChangesAccNums().size() > 0) { finished = false; } else { finished = true; } QPrinter printer; //The QPrinter class is a paint device that paints on a printer printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); printer.setOrientation(QPrinter::Portrait); printer.setPaperSize(QPrinter::Letter); QFont titleFont; titleFont.setBold(true); titleFont.setPointSize(11); titleFont.setFamily("Times New Roman"); titleFont.setKerning(false); QFont normalFont; normalFont.setPointSize(8); normalFont.setFamily("Times New Roman"); normalFont.setKerning(false); QPen lineWidth; lineWidth.setWidthF(1.25); int width = printer.width(); QPainter painter; //The QPainter class performs painting on widgets and other paint devices (such as QPrinter) //here we start painting to the printer if (!painter.begin(&printer)) return false; do { if (finished == false) { pAccForm->defaultTabValue(15); pAccForm->accountDataQuery(15, pAccForm->getMassChangesAccNums().at(counter)); pAccForm->fireBatteryQuery(15, pAccForm->getMassChangesAccNums().at(counter)); pAccForm->carbonVarLifeQuery(15, pAccForm->getMassChangesAccNums().at(counter)); pAccForm->panelInfoQuery(15, pAccForm->getMassChangesAccNums().at(counter)); pAccForm->accountBillingQuery(15, pAccForm->getMassChangesAccNums().at(counter)); pAccForm->callListQuery(15, pAccForm->getMassChangesAccNums().at(counter)); pAccForm->userPasswordListQuery(15, pAccForm->getMassChangesAccNums().at(counter)); pAccForm->zoneListQuery(15, pAccForm->getMassChangesAccNums().at(counter)); currentInxValue = 15; } int y = 30; //the function will int sectionBoxEnd = width - 10; QRectF required = QRectF(); //this represent the required rectangled size painter.setPen(lineWidth); painter.drawText(10, y, pAccForm->getAccountNum(currentInxValue)); QString date = QDate::currentDate().toString("MMM dd, yyyy"); painter.drawText(710, y, date); painter.setFont(titleFont); painter.drawText(265, y,"Proscan Security Subscriber Detail Report"); y += 20; painter.drawLine(10, y, sectionBoxEnd, y); y += 10; painter.setBrush(Qt::lightGray); QRect subInfo(10, y, sectionBoxEnd, 25); painter.drawRect(subInfo); painter.drawText(subInfo, Qt::AlignCenter, "Subscriber Information", &required); painter.setFont(normalFont); y += 45; painter.drawText(15, y, pAccForm->getAccountName(currentInxValue)); y += 15; painter.drawText(15, y, pAccForm->getAddress(currentInxValue)); QString tempLowerAddressLine = pAccForm->getCity(currentInxValue) + " " + pAccForm->getState(currentInxValue) + ", " + pAccForm->getZip(currentInxValue); y += 15; painter.drawText(15, y, tempLowerAddressLine); QString tempLocationNote = "Location: " + pAccForm->getBuildingLocation(currentInxValue); y += 30; painter.drawText(15, y, tempLocationNote);
//more stuff in between
if(i == newPage)
{
printer.newPage();
newPage += 36;
y = 5;
}
}
}
}painter.end(); //if the painting succeded return true;@
The resulting .pdf looks like:
!https://www.dropbox.com/s/c8irbgw0ozdz1gj/testresults.png?dl=0()!