Printing problem - solved
I'm trying to print an address label. Tried two different methods but neither one is perfect. Method one, using QTextDocument prints all 3 lines perfectly to a laser printer, or to Snagit, but just ejects a blank label from the label printer.
Method two prints each line of text in the same place on the same line each line over writing the other, but it does print on the label printer as well as the other devices.
There must be a simple way to get this right, but I don't see it.
Thanks for any suggestions.
Code:
// Method 1
printer
->setOrientation
(QPrinter::Landscape);
if (dialog
->exec
() != QDialog::Accepted) {
return;
}
QString cty
= "My City My State My Zipcode";
doc.setPlainText(addr);
// prints ok on the laser but nothing on the label printer
doc.print(printer);
delete dialog;
delete printer;
Code:
// Method 2
printer.
setOrientation(QPrinter::Landscape);
if (dialog
->exec
() != QDialog::Accepted) {
return;
}
list.append("My Name\n");
list.append("My Address\n");
list.append("My City My State My Zipcode");
painter.setPen(Qt::black);
printer.pageRect().left() +printer.resolution() *0.1,
printer.pageRect().top() +printer.resolution() *0.1,
printer.pageRect().width() +printer.resolution() *3.5,
printer.pageRect().height() +printer.resolution() *1.125);
painter.drawRect(textArea);
// Prints everything on the same line
for (int i = 0; i < list.size(); i++)
{
painter.
drawText(textArea,
QTextOption::WordWrap | Qt
::AlignLeft, list
[i
]);
}
delete dialog;
Update - I took a different approach and it works fine.
Code:
int x = 10;
int y = 20;
for (int i = 0; i < list.size(); i++)
{
painter.drawText(x, y, list[i]);
y = y +15;
}