[Qt-interest] QPrintPreviewDialog question
Steven Doerfler
sgd-qt at lugaru.com
Wed Mar 10 00:22:43 CET 2010
On 3/9/2010 5:47 PM, Robert Wood wrote:
> On 09/03/10 22:05, Steven Doerfler wrote:
>
>> The second parameter should be the dialog's parent window, such as your
>> main window, not what to print. You tell the preview what to show by
>> connecting a slot to the paintRequested() signal, as explained in the
>> documentation.
>>
>> Here's some sample code for using a QTextEdit with print preview:
>> http://doc.qt.nokia.com/4.6/demos-textedit-textedit-cpp.html
>>
> Thanks, Steven.
>
> Yep, I did see this and I did try:
>
> QPrinter printer(QPrinter::HighResolution);
> QPrintPreviewDialog ppd(&printer,this,Qt::Window);
> connect(&ppd, SIGNAL(paintRequested(QPrinter *)),
> SLOT(printPreview(QPrinter *)));
> ppd.exec();
>
> Then had a little routine:
>
> void invoice_dialogue::printPreview(QPrinter *printer)
> {
>
> ui->editor->print(printer);
>
> }
>
> However, this never gets called.
Did you check that connect() returns true? Maybe check
printer.isValid() too. Try constructing ppd with just &printer, no
other parameters, just to make things as simple as possible.
> I must be missing something vital here
> and I must confess I don't understand this paintRequested signal. The
> documentation says that the signal is emitted when the
> QPrintPreviewDialog needs to generate a set of preview pages. I am
> assuming that this should get called when the ppd.exec launches the
> dialogue.
Yes, it should.
If all else fails, try building the Qt sample I linked, to check that
there's not some global issue.
Steven
More information about the Qt-interest-old
mailing list