qt+zint实现打印一维条形码
2015-10-09 09:42
483 查看
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/91649552.可编译zint部分http://download.csdn.net/detail/zhang_ruiqiang/9165027
3.积分不足邮件发我,我单独发你1139760522@qq.com
相关文章推荐
- QT学习 第一章:基本对话框
- 使用Shiboken为C++和Qt库创建Python绑定
- Qt定时器和随机数详解
- Qt实现图片移动实例(图文教程)
- Qt for Android开发实例教程
- QModelIndex/Role/Model介紹<二>
- 基于PyQt5的快速开发框架QFramer
- OSX下安装PyQt
- ok6410开发板移植DirectFB手记
- 【笔记】给Qt内嵌一个Chrome吧
- 【算法】最短路径之A*搜索
- qt入门必备
- 在 Qt4 中使用 C++11
- Hello Word ~ v0.2.2 背单词软件发布 -- By WHYPRO
- ubuntu下opencv和qt的安装配置
- linux下opengl的安装(with qt)
- qt 学习小节
- QT的命名风格
- QT 中的sleep
- QT 串口的监控