Qt5中使用QPrinter和QprintDialog类

【pyqt5学习】——利用Pyqt5连接打印机(QtPrintSupport、QPrintDialog、QPageSetupDialog) 阅读详情

学习Qt过程中,做一个简单的编辑器,其中需要使用到打印文本功能,在使用Qt printer时遇到了几个麻烦。

一、在使用到QPrinter和QprintDialog类时的附加处理

①若是在qt creator中,需要在 (.pro)工程文件中加入 “QT+= printsupport”,否则会编译报错

②若是在VS环境下,只需在相应头文件中添加以下两条语句
#include <QtPrintSupport/QPrintDialog>
#include <QtPrintSupport/QPrinter>

二、在VS环境下,可能会出现如下报错:

error LNK2019: 无法解析的外部符号 “__declspec(dllimport) public: __thiscall QPrintDialog::QPrintDialog(class QPrinter *,class QWidget *)” (_imp??0QPrintDialog@@QAE@PAVQPrinter@@PAVQWidget@@@Z),该符号在函数 “protected: void __thiscall EasyEditor::showPrintText(void)” (?showPrintText@EasyEditor@@IAEXXZ) 中被引用 F:\QtSourceCode\Easy Editor\Easy Editor\EasyEditor.objEasy Editor

在这里插入图片描述
错误2019,一般都是由于缺少相应的库文件。
解决办法:

右击项目,选择“属性”–>“链接器”–>“输入”–>“附加依赖项”–>“编辑”

在最后添加上“Qt5PrintSupport.lib”即可。
在这里插入图片描述

写此以记之,如有不对,欢迎指出。


作者:刘知安
来源:优快云
原文:https://blog.youkuaiyun.com/qq_37174526/article/details/79132051

使用QT5 PrintSupport打印和预览标签 由于需要做一个不干胶标签纸的打印程序,所以用到了PrintSupport。在这里简单记录下,以备自己查看。 一开始只是实现了标签打印功能,后来发现每次修改了标签都要打印出来看效果(节约一些标签纸,因为是特殊印刷的标签纸,数量有限),想到了用PrintSupport中的QPrintPreviewWidget或者QPrintPreviewDialog来实现预览。 不干胶标签的实际尺寸为100x80mm... 阅读详情

相关推荐

Qt 关于Qt5中QPrinter问题

在用Qt做记事本的时候出现:QPrinter:no such file or directory 的错误,解决方法如下: 在.pro文件中添加下面一行代码: qtHaveModule(printsupport): QT += printsupport 就可以了,头文件不需要改。这是因为Qt 5中将所有打印的相关类都放到了Qt Print Support模块造成的。

mojianc的专栏 8556

Qt打印功能;QPrintPreviewWidget使用;QPrintDialog使用;QPrintPreviewDialog使用;

一、QPrintDialog使用 在需要使用的地方直接使用: QPrinter printerpng;//创建一个打印机 QPrintDialog dlg(&printerpng);//创建打印页面,并传入打印机 qDebug()<<dlg.exec();//显示打印界面,返回值判断点击的是0表示取消,1表示打印 //界面显示后,可以通过printerpng获取设置的打印页面信息 qDebug()<<"打印页面设置的纸张页面布局:

qq_36626674的博客 9568

第15章 基于QT5打印机设备开发

第15章 基于QT5打印机设备开发 QT5支持打印机的相关类如下: QPrinter类是在打印机上绘制的绘图设备。 QPrintDialog类提供了一个用于指定打印机配置的对话框。 QPrintPreviewDialog类提供了一个对话框,用于预览和配置打印机输出的页面布局。 15.1 QPrinter类 头文件 :#include <QPrinter> qmake :QT += printsupport 继承类 :QPagedPaintDevice 15.1.1 QPr

1013

clion+vs编译器+Qt5中使用QPrinter和QprintDialog类

学习Qt过程中,实现用一个编辑器,其中需要使用到打印文本功能,在使用Qt printer时遇到了几个麻烦。 1.在使用到QPrinter和QprintDialog类时的附加处理 ①若是在qt creator中,需要在 (.pro)工程文件中加入 “QT+= printsupport”,否则会编译报错 ②若是在VS编译器环境下,只需在相应头文件中添加以下两条语句 #include <QtPrintSupport/QPrintDialog> #include <QtPrintSupport/Q

qq_41827817的博客 1422

HFSS螺旋线圈的设计与仿真

undefined.全局变量在这里进行设置:Project/Project Properties, browse and setup the global variables.undefined.方程中的局部变量设置:HFSS/Design Properties, browse and setup the local variables。按照下图填写曲线的方程内容:fill the parameters according to the setup in the following picture。

johnboat的专栏 3845

PostGIS 小白入门详细指南

PostGIS 是 PostgreSQL 的一个扩展,它将 PostgreSQL 转变为一个功能强大的空间数据库,使其能够存储、查询和分析地理空间数据。PostGIS 遵循开放地理空间联盟(OGC)的标准,支持各种空间数据类型和操作,如点、线、多边形、缓冲区、空间连接等。存储各种空间数据类型(如几何类型和地理类型)空间索引,提高查询性能丰富的空间函数和操作支持投影和坐标系统转换城市规划与管理环境监测与分析物流与运输优化地图制作与可视化位置服务与导航。

落魄书生的职业学习生涯 1万+

Qt5中QPrinter类和QPinterDialog类

QPrinter:no such file or directory 的错误 Qt5中将QPrinter、QPrintDialog等类归到了printsupport模块中。 如果项目中需要这2个头文件 则需要在工程文件.pro中加入 QT+=printsupprot 。否则会出错 修改完要先qmake一下在运行,不然修改无效

会飞的CC猫之愉快Qt学习笔记 4858

告别天价授权!手把手教你用TwinCAT 3.1搭建EtherCAT主站(Windows 10/11保姆级教程)

本文详细介绍了如何在Windows 10/11系统上使用TwinCAT 3.1免费搭建EtherCAT主站,帮助中小企业和个人开发者低成本实现工业自动化。从环境准备、许可证策略到安装配置和实战开发,提供保姆级教程,涵盖PLC编程、运动控制及硬件选型建议,助您轻松入门工业控制领域。

weixin_30664615的博客 362

Qt5文件和图像打印

添加头文件 #include &lt;QPrintDialog&gt; #include &lt;QPrinter&gt; #include &lt;QPainter&gt; Qt5中将Qprinter、QPrintDialog等类归入到了printsupport模块中,如果在项目中引入了上面的两个头文件,还需要在工程文件(.pro文件)中加入QT+=printsupport,否则编译会出错...

zhengluanfeng1985的博客 3333

Mathtype公式下标深度调整技巧:解决固定行距下的显示不全问题

本文针对在Word等文档中设置固定行距时,Mathtype公式下标显示不全的问题,提供了专业解决方案。核心在于调整Mathtype软件内部的“下标深度”参数,通过修改单个公式或批量格式化全文,使公式完美适配固定行距,确保下标清晰完整,且不影响文档整体排版。

pepsi的博客 1500

博途WinCC多语言项目配置指南

在博途(TIA Portal)中为WinCC项目配置多语言功能,需通过系统化步骤实现界面文本的动态切换。

dhaimo的博客 2472

Qt5 文本打印

打印的代码如下:void ImageProcessor::ShowPrintText() { QPrinter printer; QPrintDialog printDialog(&printer,this); if(printDialog.exec()) { QTextDocument *doc=showWidget->text->document

dreament的专栏 2318

MAC M1用户必看:UTM虚拟机安装Win11全流程避坑指南(附驱动下载)

本文为MAC M1用户提供UTM虚拟机安装Win11的完整指南,涵盖镜像准备、驱动优化及性能调优等关键步骤。特别针对TPM 2.0验证、网络连接等常见问题提供解决方案,帮助用户高效运行Windows 11 ARM版。

weixin_29204205的博客 339

Qt打印功能

文本打印 文本打印要调出文本打印框,这时要使用QPrintDialog QPrintDialog要将QPrinter类的一个对象作为参数,打印文本时调用print函数也要将QPrinter类的对象作为参数,所以要先声明一个QPrinter对象

aa134159的博客 761

Claude Code 源码一夜流出:会看热闹的人很多,会读源码的人很少

摘要:Claude Code源码意外泄露后,作者分享了高效的源码学习方法:1)Fork仓库保存代码;2)使用Qoder的Repo Wiki功能生成结构化文档和UML图;3)基于Wiki创建可复用的Skill。这种方法比直接让AI总结代码更系统深入,并推荐了可视化学习项目辅助理解。文章强调实践的重要性,提供了具体工具和操作指南。

720

【C++】构造函数之初始化列表(Initialization list of constructors)

本讲主要是构造函数的初始化列表的讲节,但是本节很重要,可以关乎后面写项目

m0_62599305的博客 2233

QPrinter和QprintDialog类头文件无法加载

学习Qt过程中,做一个简单的编辑器,其中需要使用到打印文本功能,在使用Qt printer时遇到了几个麻烦。 一、在使用到QPrinter和QprintDialog类时的附加处理 ①若是在qt creator中,需要在 (.pro)工程文件中加入 “QT+= printsupport”,否则会编译报错 ②若是在VS环境下,只需在相应头文件中添加以下两条语句 #include <QtPrin...

aaron1996123456的博客 3238

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

QPrinter和QPrintDialog的使用举例

#ifndef QT_NO_PRINTER QPrinter printer(QPrinter::HighResolution); qDebug()true "PDF-XChange 4.0" QPrintDialog dialog(&printer, this); if (dialog.exec()) { qDebug()true "PDF-XC

u013639526的专栏 7488

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

「QT」标准对话框类 之 QPrintDialog 打印对话框

默认构造函数创建一个没有关联打印机对象的打印对话框。带有打印机对象的构造函数创建一个与给定打印机对象关联的打印对话框。QPrintDialog提供了丰富的公有函数,用于设置和获取对话框的属性,以及控制对话框的行为。:设置与打印对话框关联的打印机对象。:获取与打印对话框关联的打印机对象。:设置打印对话框的选项。:检查打印对话框的选项是否已设置。:获取打印对话框的选项。:设置对话框上“确定”按钮的图标。:获取对话框上“确定”按钮的图标。:设置对话框上“取消”按钮的图标。

何曾参静谧的博客 1493

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

QT Creator中关于QPrinter和QPrintDialog的使用

前言 今天实训课上做一个Easy Word,然后做到打印文本的功能时,发现这两个头文件咋不能用,之后才知道还要进行一些附加处理 实现效果: 1.使用QPrinter和QprintDialog类时的附加处理 ①若是在QT Creator中,需要在 (.pro)工程文件中加入 “QT+= printsupport ”,否则会编译报错 ②若是在VS环境下,只需在相应头文件中添加以下两条...

逝不等琴生的博客 4453

Qt实现保存、浏览、预览、打印功能

        Qt提供了以文本、图片、HTML等方式来实现对文档的操作,主要用到了QPrinter类和QPainter类,用到了QFileDialog文件窗口、QPrintPreviewDialog预览窗口类和QPrintDialog打印窗口类,Qt5也提供了QPdfWriter类来实现对pdf的操作,这里并不包括打开pdf文件,Qt没有提供任何方法来直接像文件浏览器一样打开pdf文件,可以用第...

画茧自缚 2万+

QT5使用QPrinter QPrintDialog报错

错误信息: undefined reference to `_imp___ZN8QPrinterC1ENS_11PrinterModeE undefined reference to `_imp___ZN12QPrintDialogC1EP8QPrinterP7QWidget undefined reference to `_imp___ZN20QAbstractPrintDialog16addE...

joe8910的博客 1850

Qt使用Qpainter绘制并调用QPrinter打印

Qt使用Qpainter绘制并调用QPrinter打印

qianniulaoren的博客 1609

Python Qt GUI设计:QPrinter打印图片类(基础篇—21)

打印图像是图像处理软件中的一个常用功能,打印图像实际上是在QPaintDevice中画图,与平常在QWidget、QPixmap和Qlmage中画图一样,都是创建一个QPainter对象进行画图的,只是打印使用的是QPrinter,它本质上也是一个QPaintDevice(绘图设备)。

不脱发的程序猿 2万+
上一篇: QTableWidget点击表头按列排序
下一篇: QTableWidget 排序功能跟踪
我与四十大盗
博客等级 码龄8年 62粉丝 77原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值