qt+zint实现打印一维条形码
来源:互联网 发布:centos 6.5网络配置ip 编辑:程序博客网 时间:2024/06/08 00:56
1.需求
需要将小票号打印成条形码,退换货时通过扫描枪直接扫描不用人工输入进行退货和换货,加快速度
2.实现
这里通过zint生成条形码图片,通过qt将图片绘制到打印纸上实现,也可以直接在打印纸上进行绘制线条,因人而异
3.代码片段
打印小票号
void mytestimage::printBarcode(const QString &strTitle){ //打印部分 //这里先生成图片 QString strImagePath(""); strImagePath = QCoreApplication::applicationDirPath() + "//test.png"; struct zint_symbol * my_symbol = ZBarcode_Create(); my_symbol->symbology = BARCODE_CODE93;//BARCODE_CODE11; strcpy(my_symbol->outfile, strImagePath.toLocal8Bit().toStdString().c_str()); ZBarcode_Encode(my_symbol, (unsigned char*)strTitle.toLocal8Bit().toStdString().c_str(), 0); ZBarcode_Print(my_symbol, 0); ZBarcode_Delete(my_symbol); //绘制 QPrinter printer; QPrintDialog printdialog(&printer, this); if (printdialog.exec()) { //这里我如何保证不进行拉伸呢 //QString strname = printer.printerName(); int dpi = printer.logicalDpiX(); int nmm = printer.paperRect(QPrinter::Millimeter).width(); int width = std::min(nmm, 80)*(dpi*1.0/25.4); //这里选择80mm纸张 QPainter painter(&printer); QImage image(strImagePath, "PNG"); QRect rt1 = image.rect(); QRect rtwindow = painter.window(); QRect rtview = painter.viewport(); int nmax = 0; if (image.width() + 20 < width) nmax = std::max(image.width() + 20, width); else nmax = std::min(image.width() + 20, width); QRect rtimage(0, 0, nmax, rtwindow.height()); QRect rtimageview(0, 0, nmax, rtview.height()); int nmin = std::min(image.width(), nmax - 80); QRectF rtdes(40, 10, nmin, 100); QRectF rtsrc(0, 0, image.width(), image.height()); painter.setWindow(rtimage); painter.setViewport(rtimageview); painter.drawImage(rtdes, image, rtsrc); painter.setWindow(rtwindow); painter.setViewport(rtview); } //这里再删除图片 //QFile file(strImagePath); //QFile::remove(strImagePath);}
4.备注
1.测试项目地址http://download.csdn.net/detail/zhang_ruiqiang/9164955
2.可编译zint部分http://download.csdn.net/detail/zhang_ruiqiang/9165027
3.积分不足邮件发我,我单独发你1139760522@qq.com
3 0
- qt+zint实现打印一维条形码
- .net实现生成及打印条形码功能
- .net实现生成及打印条形码功能
- .net实现生成及打印条形码功能
- .net实现生成及打印条形码功能
- web打印实现方案 Lodop 以及条形码
- Java 条形码生成(一维条形码)
- Java 条形码生成(一维条形码)
- Java 条形码生成(一维条形码)
- 打印条形码
- 打印条形码
- J2EE 使用maskbarcode.jar实现一维条形码
- Delphi 调用Zint 实现二维码功能
- PB中利用字体实现EAN13条形码的打印
- 使用vs2008结合codesoft来实现条形码的打印
- winfrom 实现条形码批量打印以及将条形码信息生成PDF文件
- c#打印条形码
- php条形码打印
- LeetCodeOJ.Longest Palindromic Substring
- dev(八):实战:使用udevadm修改usb优盘在/dev下的名字
- character_set_server
- JAVA JDBC 调用存储过程 传参数
- centos7 开机默认进入字符界面
- qt+zint实现打印一维条形码
- 一致性hash算法 - consistent hashing
- 字符串移位
- easyui 页面跳转,关闭刷新面板
- springmvc+mybatis 无极限树形结构菜单
- iOS App开发那些事:如何选择合适的人、规范和框架?
- 拓展C++ STL功能,函数适配器,复合函数composite
- 蜗轮蜗杆联动动画
- Struts2国际化支持(中英文选择)