请教 QT5.2打印 页面设置无效

Babyboymanold 2017-08-18 10:13:20
请教各位:

环境:QT5.2、 Windows平台、 网络打印机

问题:
1,使用QPageSetupDialog可以修改页面方向,却不能修改其他页面信息?
2:在QPageSetupDialog中选择其他尺寸的纸张时程序崩溃,为什么?如何获取打印机支持哪些纸张?

源码:
void MainWindow::on_btn_page_setup_clicked()
{
qreal left, top, right, bottom;

qDebug() << m_printer.printerName() << __FILE__ << __LINE__; //m_printer为头文件中定义的私有成员,只在本函数调用
qDebug() << m_printer.supportedPaperSources() << __FILE__ << __LINE__;
qDebug() << m_printer.supportedResolutions() << __FILE__ << __LINE__;
qDebug() << m_printer.orientation() << __FILE__ << __LINE__;
qDebug() << m_printer.fullPage() << __FILE__ << __LINE__;
qDebug() << m_printer.paperName() << __FILE__ << __LINE__;

qDebug() << QString("确定前默认为A4");
qDebug() << m_printer.paperSize() << __FILE__ << __LINE__; //0/A4
qDebug() << m_printer.paperRect() << __FILE__ << __LINE__;
qDebug() << m_printer.pageRect() << __FILE__ << __LINE__;
m_printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
qDebug() << left << top << right << bottom << __FILE__ << __LINE__;

QPageSetupDialog pageSetUpdlg(&m_printer, this);
if (pageSetUpdlg.exec() == QDialog::Accepted)
{
qDebug() << QString("按下确定");
qDebug() << m_printer.printerName() << __FILE__ << __LINE__;
qDebug() << m_printer.supportedPaperSources() << __FILE__ << __LINE__;
qDebug() << m_printer.supportedResolutions() << __FILE__ << __LINE__;
qDebug() << m_printer.orientation() << __FILE__ << __LINE__;
qDebug() << m_printer.fullPage() << __FILE__ << __LINE__;
QString strPaperName = m_printer.paperName();
qDebug() << strPaperName << __FILE__ << __LINE__; //
//m_printer.setPaperName(strPaperName);

qDebug() << QString("确定后");
qDebug() << m_printer.paperSize() << __FILE__ << __LINE__; //30/Custom
qDebug() << m_printer.paperRect() << __FILE__ << __LINE__;
qDebug() << m_printer.pageRect() << __FILE__ << __LINE__;
m_printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
qDebug() << left << top << right << bottom << __FILE__ << __LINE__;

//The page size can also be specified in millimeters using setPageSizeMM(). In this case the page size enum is set to Custom.
qDebug() << QString("确定后用setPaperSize()设置A4");
m_printer.setPaperSize(QPrinter::A4);
qDebug() << m_printer.paperSize() << __FILE__ << __LINE__; //0/A4
qDebug() << m_printer.paperRect() << __FILE__ << __LINE__;
qDebug() << m_printer.pageRect() << __FILE__ << __LINE__;
m_printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
qDebug() << left << top << right << bottom << __FILE__ << __LINE__;
}
else
{
qDebug() << QString("按下取消");
qDebug() << m_printer.printerName() << __FILE__ << __LINE__;
qDebug() << m_printer.supportedPaperSources() << __FILE__ << __LINE__;
qDebug() << m_printer.supportedResolutions() << __FILE__ << __LINE__;
qDebug() << m_printer.orientation() << __FILE__ << __LINE__;
qDebug() << m_printer.fullPage() << __FILE__ << __LINE__;
qDebug() << m_printer.paperName() << __FILE__ << __LINE__; //

qDebug() << QString("取消后");
qDebug() << m_printer.paperSize() << __FILE__ << __LINE__; //0/A4
qDebug() << m_printer.paperRect() << __FILE__ << __LINE__;
qDebug() << m_printer.pageRect() << __FILE__ << __LINE__;
m_printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
qDebug() << left << top << right << bottom << __FILE__ << __LINE__;

//The page size can also be specified in millimeters using setPageSizeMM(). In this case the page size enum is set to Custom.
qDebug() << QString("取消后用setPageSizeMM()设置A4");
m_printer.setPageSizeMM(QSizeF(210, 297));
qDebug() << m_printer.paperSize() << __FILE__ << __LINE__; //30/Custom
qDebug() << m_printer.paperRect() << __FILE__ << __LINE__;
qDebug() << m_printer.pageRect() << __FILE__ << __LINE__;
m_printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
qDebug() << left << top << right << bottom << __FILE__ << __LINE__;
}

//qt如何获取打印机支持的纸张大小,设置A6纸时崩溃
//QPrinter::A4 0 210 x 297 mm, 8.26 x 11.69 inches
}


图片:


输出:
1,按确定按钮输出:
引用
Starting E:\ProjectsQt\build-QtPrint-Desktop_Qt_5_2_0_MinGW_32bit-Release\release\QtPrint.exe...
"\\10.10.100.120\PRINTER-RD" ..\QtPrint\mainwindow.cpp 357
(6, 257, 258, 259, 260, 1000, 3) ..\QtPrint\mainwindow.cpp 358
(600, 1200) ..\QtPrint\mainwindow.cpp 359
0 ..\QtPrint\mainwindow.cpp 360
false ..\QtPrint\mainwindow.cpp 361
"A4" ..\QtPrint\mainwindow.cpp 362
"确定前默认为A4"
0 ..\QtPrint\mainwindow.cpp 365
QRect(0,0 794x1122) ..\QtPrint\mainwindow.cpp 366
QRect(16,16 762x1090) ..\QtPrint\mainwindow.cpp 367
4.23001 4.23001 4.23001 4.23001 ..\QtPrint\mainwindow.cpp 369
"按下确定"
"\\10.10.100.120\PRINTER-RD" ..\QtPrint\mainwindow.cpp 375
(6, 257, 258, 259, 260, 1000, 3) ..\QtPrint\mainwindow.cpp 376
(600, 1200) ..\QtPrint\mainwindow.cpp 377
0 ..\QtPrint\mainwindow.cpp 378
false ..\QtPrint\mainwindow.cpp 379
"A4" ..\QtPrint\mainwindow.cpp 381
"确定后"
30 ..\QtPrint\mainwindow.cpp 385
QRect(0,0 -1x-1) ..\QtPrint\mainwindow.cpp 386
QRect(0,0 -1x-1) ..\QtPrint\mainwindow.cpp 387
0 0 0 0 ..\QtPrint\mainwindow.cpp 389
"确定后用setPaperSize()设置A4"
0 ..\QtPrint\mainwindow.cpp 394
QRect(0,0 794x1122) ..\QtPrint\mainwindow.cpp 395
QRect(16,16 762x1090) ..\QtPrint\mainwindow.cpp 396
4.23001 4.23001 4.23001 4.23001 ..\QtPrint\mainwindow.cpp 398
E:\ProjectsQt\build-QtPrint-Desktop_Qt_5_2_0_MinGW_32bit-Release\release\QtPrint.exe exited with code 0

2,按取消按钮输出:
引用
Starting E:\ProjectsQt\build-QtPrint-Desktop_Qt_5_2_0_MinGW_32bit-Release\release\QtPrint.exe...
"\\10.10.100.120\PRINTER-RD" ..\QtPrint\mainwindow.cpp 357
(6, 257, 258, 259, 260, 1000, 3) ..\QtPrint\mainwindow.cpp 358
(600, 1200) ..\QtPrint\mainwindow.cpp 359
0 ..\QtPrint\mainwindow.cpp 360
false ..\QtPrint\mainwindow.cpp 361
"A4" ..\QtPrint\mainwindow.cpp 362
"确定前默认为A4"
0 ..\QtPrint\mainwindow.cpp 365
QRect(0,0 794x1122) ..\QtPrint\mainwindow.cpp 366
QRect(16,16 762x1090) ..\QtPrint\mainwindow.cpp 367
4.23001 4.23001 4.23001 4.23001 ..\QtPrint\mainwindow.cpp 369
"按下取消"
"\\10.10.100.120\PRINTER-RD" ..\QtPrint\mainwindow.cpp 403
(6, 257, 258, 259, 260, 1000, 3) ..\QtPrint\mainwindow.cpp 404
(600, 1200) ..\QtPrint\mainwindow.cpp 405
0 ..\QtPrint\mainwindow.cpp 406
false ..\QtPrint\mainwindow.cpp 407
"A4" ..\QtPrint\mainwindow.cpp 408
"取消后"
0 ..\QtPrint\mainwindow.cpp 411
QRect(0,0 794x1122) ..\QtPrint\mainwindow.cpp 412
QRect(16,16 762x1090) ..\QtPrint\mainwindow.cpp 413
4.23001 4.23001 4.23001 4.23001 ..\QtPrint\mainwindow.cpp 415
"取消后用setPageSizeMM()设置A4"
30 ..\QtPrint\mainwindow.cpp 420
QRect(0,0 794x1123) ..\QtPrint\mainwindow.cpp 421
QRect(0,0 794x1123) ..\QtPrint\mainwindow.cpp 422
0 0 0 0 ..\QtPrint\mainwindow.cpp 424
E:\ProjectsQt\build-QtPrint-Desktop_Qt_5_2_0_MinGW_32bit-Release\release\QtPrint.exe exited with code 0

...全文
456 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Babyboymanold 2017-08-20
  • 打赏
  • 举报
回复
为什么页面设置对话框选择的是A4纸,代码里获取的paperSize却是负数呢?

16,175

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧