16,216
社区成员
发帖
与我相关
我的任务
分享
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
}