2019独角兽企业重金招聘Python工程师标准>>>
配置文件加入打印机支持:
QT += printsupport
1、打印图片
打印图片所需头文件:
#include <QPixmap>
#include <QPrinter>
#include <QPainter>
打印图片代码:
QString fileName = "E:\\images\\edit_undo.png"; //打印图片路径if(fileName != NULL) {QPixmap pixmap(fileName);QPrinter printer;printer.setPrinterName("DASCOM DS-650Pro"); //打印机名称QPainter painter(&printer);painter.drawText(150, 150, fileName);painter.drawPixmap(50, 100, pixmap);}
2、打印文字
打印文字代码:
QPrinter printer;printer.setPrinterName("DASCOM DS-650Pro"); //打印机名称QPainter painter(&printer);// 设置画笔颜色painter.setPen(QColor(0, 160, 230));// 设置字体:微软雅黑、点大小50、斜体QFont font;//font.setFamily("Microsoft YaHei");font.setFamily("宋体");font.setPointSize(15);font.setItalic(true);painter.setFont(font);QPoint point;point.setX(150);point.setY(150);painter.drawText(point, "你好 world");point.setX(250);point.setY(250);font.setPointSize(10);font.setItalic(false);painter.setFont(font);painter.drawText(point, "你好 world");