Using Qt 5.2 on Windows 7 64bit. I am building a 32-bit app
I am trying to get printing working. I have a weird problem that I can't seem to figure out. If I create a QPrinter instance using this code:
QPrinter * pPrinter = new QPrinter( QPrinterInfo::defaultPrinter(), QPrinter::ScreenResolution );
To copy to clipboard, switch view to plain text mode
and then look at the values for
QPrinter::pageRect( QPrinter::Inch ) and QPrinter::paperRect( QPrinter::Inch )
To copy to clipboard, switch view to plain text mode
I get the results I would expect for my default printer (Letter size paper, 8.5 x 11 inches).
If I then pass this QPrinter instance to QPrintDialog and open it:
if ( pPrinter && pPrinter->isValid() )
{
connect( &dlg,
SIGNAL( accepted
( QPrinter * ) ),
this,
SLOT( onPrinterAccepted
( QPrinter * ) ) );
dlg.exec();
}
if ( pPrinter && pPrinter->isValid() )
{
QPrintDialog dlg( pPrinter );
dlg.setOptions( QAbstractPrintDialog::None );
connect( &dlg, SIGNAL( accepted( QPrinter * ) ), this, SLOT( onPrinterAccepted( QPrinter * ) ) );
dlg.exec();
}
To copy to clipboard, switch view to plain text mode
and then examine those same values in the onPrinterAccepted() slot, those values are now completely messed up, typically QRectF( 0.0, 0.0, -0.0104166, -0.0104166)
This happens even if I do nothing at all with the dialog - let it display, don't do anything except click the "Print" button.
If I create the QPrintDialog without passing it a QPrinter instance:
connect( &dlg,
SIGNAL( accepted
( QPrinter * ) ),
this,
SLOT( onPrinterAccepted
( QPrinter * ) ) );
dlg.exec();
QPrintDialog dlg;
dlg.setOptions( QAbstractPrintDialog::None );
connect( &dlg, SIGNAL( accepted( QPrinter * ) ), this, SLOT( onPrinterAccepted( QPrinter * ) ) );
dlg.exec();
To copy to clipboard, switch view to plain text mode
I get exactly the same behavior. If I select a different printer from the dialog, it doesn't matter what printer I choose, I still get the same messed up results if I let the dialog use my QPrinter instance or if I look at the one returned to the slot.
Changing the Unit type in the call to
QPrinter::pageRect()
To copy to clipboard, switch view to plain text mode
results in different values being returned, but they are always wrong and always a negative height and width.
I have confirmed that there is only one plugins/printsupport directory on my machine, so it can't be pulling in a mis-matched "windowsprintersupport" DLL
I do not know if it is relevant, but the code that does the printing is in a static library, linked into my app. The Print QAction's triggered() signal in the GUI is connected to a slot in the library that kicks off the printing.
Any ideas what I might be doing wrong?
Bookmarks