Qt:在打印机点阵上打印 [英] Qt: printing on printer dot matrix

查看:102
本文介绍了Qt:在打印机点阵上打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Qt 将一些字符串打印到打印机点阵 LX-300+,但字体似乎倾斜.有些用户也有这个问题 http://www.qtcentre.org/threads/11814-printing-program-in-LX-300-(dot-matrix-printer)-problem 但我直到现在才找到解决方案.请帮我解决这个问题.如果这是 Qt 错误,我是否需要使用其他框架或 .net 创建 dll 或应用程序?这是我的代码

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);

我使用的是 Qt5.4.0 mingw491 32 OS win 7 64bit

i'm using Qt5.4.0 mingw491 32 OS win 7 64bit

推荐答案

我可以像这个伪代码一样直接使用Windows API解决这个问题

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);

希望这对某人有帮助

这篇关于Qt:在打印机点阵上打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆