View Full Version : Setting paper size of QPrinter

20th June 2018, 23:10

I'm trying to set the paper size of a QPrinter but I'm having an issue.
The printer I'm using is a photo printer (mitsubishi cp9550dw) and it supports photo strips. I'm trying to set the paper size to the photo strip but it doesn't work, I can set it to all other values though.
When I list all the supported sizes I get this as a result.

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)

As you can see They all have a different keys except the two in Bold. I thing what's happening is that when I call printer->setPageSize(pageSize);, It looks in a table and selects the first match of the key which is a regular photo and not the photo strip I want. The dimensions are the same but the photostrip gets cut in half, wich isn't happening because of this issue.

Any ideas on how to fix this? Is there another way to change the paper size?


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 ){
qDebug() << "set paper size to " + pageSize.name()<<" -> "<< printer->paperName();