设置QPrinter的纸张尺寸

时间:2018-06-21 18:59:11

标签: c++ qt printing qprinter

我正在尝试设置QPrinter的纸张尺寸,但是出现问题。 我使用的打印机是照片打印机(三菱cp9550dw),它支持照片带。我正在尝试将纸的尺寸设置为相纸,但是它不起作用,不过我可以将其设置为所有其他值。

当我列出所有受支持的尺寸时,我将得到以下结果:

  • QPageSize(“ 9x13(3.5x5”)“,key =” Custom.258x377“,258x377pt,id = 30)
  • QPageSize(“ 10x15(4x6”)“,key =” Custom.295x448“,295x448pt,id = 30)
  • QPageSize(“ 13x18(5x7”)“,key =” Custom.377x510“,377x510pt,id = 30)
  • QPageSize(“ 15x20(6x8”)“,key =” Custom.448x581“,448x581pt,id = 30)
  • QPageSize(“ 15x21(6x8.5”)“,key =” Custom.448x615“,448x615pt,id = 30)
  • QPageSize(“ 15x23(6x9”)“,key =” Custom.448x652“,448x652pt,id = 30)
  • QPageSize(“ 5x15x2 Type1(2x6” x2)“,key =” Custom.295x448“,295x448pt,id = 30)
  • QPageSize(“ 5x15x2 Type2(2x6” x2)“,key =” Custom.147x448“,147x448pt,id = 30)

您将看到,除了以粗体显示的两个键以外,它们都有不同的键。我所发生的事情是,当我调用printer-> setPageSize(pageSize);时,它会在表中查找并选择键的第一个匹配项,这是常规照片,而不是我想要的照片带。尺寸是一样的,但是照片带被切成了两半,因为这个问题,这是没有发生的。

关于如何解决此问题的任何想法?还有其他改变纸张尺寸的方法吗?

代码:

Qt代码:

QPrinter *printer;
QPrinterInfo _pinfo;

QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
foreach (const QPrinterInfo &printerInfo, printers){
    if( printerInfo.description() == _printer_name ){
        printer = new QPrinter(printerInfo);
        _pinfo = printerInfo;
    }
}
QList<QPageSize> sizes = _pinfo.supportedPageSizes();
qDebug() << printer->paperName();
qDebug() << _paper_name;
foreach (const QPageSize &pageSize, sizes){
    qDebug() << pageSize;// + ", "+pageSize.key() + ", "+pageSize.id() + ", "+pageSize.isValid();
    if( pageSize.name() == _paper_name ){
        printer->setPageSize(pageSize);
        qDebug() << "set paper size to " + pageSize.name()<<"  ->  "<< printer->paperName();
    }
}

0 个答案:

没有答案