Printing multiline tickets
Unsolved
General and Desktop
-
Hi,
I'm using a printer VKP80III to print tickets/recipes.
And for now, the code look like this:QPrinterInfo _printer = ...; ... QPrinter printer(_printer); printer.setPaperSize(QSize(80, 120), QPrinter::Millimeter); printer.setPageMargins(15, 15, 15, 15, QPrinter::Millimeter); printer.setFullPage(true); QString tmp = message; tmp.replace("\n", "\r\n"); QPainter painter; painter.begin(&printer); painter.setFont(QFont("Tahoma", 8)); painter.drawText(QPoint(0, 0), tmp); painter.end();
My paper is 80x120 mm.
I expect an output like:-------------------------------- ANY BANK -------------------------------- TERMINAL # 123456 SEQUENCE # 12345 AUTH # 25688KK DATE 11/11/2014 TIME 16:52:24 CARD NUMBER **** **** **** 0069 CUSTOMER NAME BERNARD MADOFF DISPENSED AMOUNT $200.00 REQUESTED AMOUNT $200.00 FROM ACCOUNT CHECKING TERMINAL FEE $1.00 TOTAL AMOUNT $201.00 BALANCE $22,234,396.82 --------------------------------.
But only get this:
-------------------------------- ANY BANK -------------------
The rest doesn't print since it never go to a new line.
Does anyone have a solution for this?Thanks in advance.
ps: The ticket content is just a test, I'm not working for a bank.
-
QPainter::drawText(const QPoint & position, const QString & text)
does not support newlines, you need to use the
void QPainter::drawText(const QRectF & rectangle, int flags, const QString & text)
version of that function to get those to work.