问题
I'm trying to print some string to a printer dot matrix LX-300+ using Qt but it seems that the font is skewed. Some users also have this problem http://www.qtcentre.org/threads/11814-printing-program-in-LX-300-(dot-matrix-printer)-problem but i can't find the solutions until now. Please help me to address this problem. Do i need to create a dll or application using other framework maybe .net if this is Qt bug? Here is my code
QTextDocument document;
QTextCursor cursor = QTextCursor(&document);
QFont font = QFont("Courier");
QTextCharFormat format = QTextCharFormat();
format.setFont(font);
cursor.setCharFormat(format);
cursor.insertText("lorem ipsum dolor sit amit amit ");
QPrinter printer(QPrinter::ScreenResolution);
printer.setPrinterName(ui->ddlPrinter->currentData().toString());
printer.setColorMode(QPrinter::GrayScale);
printer.setPageSize(QPrinter::A4);
printer.setFullPage(false);
QPrintDialog dialog(&printer, this);
document.print(&printer);
i'm using Qt5.4.0 mingw491 32 OS win 7 64bit
回答1:
I can solve this problem using Windows API directly like this pseudo code
OpenPrinter(name,&hPrinter, NULL);
dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo );
bStatus = StartPagePrinter(hPrinter);
BOOL bStatus = WritePrinter(hPrinter,(LPVOID)buffer,text.length(),&dwBytesWritten);
hope this help someone
来源:https://stackoverflow.com/questions/32310797/qt-printing-on-printer-dot-matrix