View Full Version : Pratical example of QPrintPreviewDialog
vcp
18th September 2008, 19:55
Hi all,
I'm needing of the pratical example of how use the class QPrintPreviewDialog. I did not find no documentation about this. I need a pratical example.
I think that the Throlltec's must update the samples programs.
jacek
19th September 2008, 00:00
Come on! All this class has is a constructor and a signal.
The docs describe three steps you need to follow. Which one you don't understand?
patrik08
19th September 2008, 08:24
Hi all,
I'm needing of the pratical example of how use the class QPrintPreviewDialog. I did not find no documentation about this. I need a pratical example.
I think that the Throlltec's must update the samples programs.
this piece of code is from
http://fop-miniscribus.googlecode.com/svn/trunk/OO_Widged/demo/textedit.cpp
its only a qt4.4.1/demos/textedit + OpenOffice odt reader
to get full svn code open:
http://www.qt-apps.org/content/show.php/OpenDocument+format+Reader%2BWriter+odt?content=80 650
void TextEdit::filePrintPreview()
{
#ifndef QT_NO_PRINTER
QPrinter printer(QPrinter::HighResolution);
QPrintPreviewDialog preview(&printer, this);
preview.setWindowFlags ( Qt::Window );
connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *)));
preview.exec();
#endif
}
void TextEdit::printPreview(QPrinter *printer)
{
#ifndef QT_NO_PRINTER
textEdit->print(printer);
#endif
}
IMO: if you like to build static QPrintPreviewDialog append his icon
vcp
19th September 2008, 12:27
Thanks to patrik08 by your help.
I think that the objective of this forum be help the persons and not depreciate the questions, by more samples that they be.
rosenth
19th May 2010, 22:11
hi.
why the printer in this function:
void dlg_account::on_btn_print_clicked()
{
QPrinter printer(QPrinter::HighResolution);
printer.setFullPage( true );
QPrintPreviewDialog preview(&printer, this);
preview.setWindowFlags ( Qt::Window );
connect(&preview, SIGNAL(paintRequested(QPrinter* )), SLOT(print(QPrinter* )));
preview.exec();
}
isnt recognised in the:
void dlg_account::print( QPrinter* printer)
{
QPainter *painter=new QPainter(printer);
QRect paper = printer->pageRect();
painter->setPen(Qt::black);
painter->setFont(QFont("Sans",14,0,0));
painter->drawText(QRect(0,0,100,100),Qt::AlignLeft||Qt::Ali gnTop,"page1");
}
pcheng
24th July 2012, 16:24
I am having difficulties with implementing the QPrintPreviewDialog.
I included this code in the function that calls the printing:
QPrinter printer(QPrinter::HighResolution);
QPrintPreviewDialog ppd(&printer,this,Qt::Window);
connect(&ppd, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *)));
ppd.exec();
And I also added this function at the end:
void PackageDialog::printPreview( QPrinter* printer)
{
ui->editor->print(printer);
}
It says that the ui->editor part should be the parent of the dialog box but I am not sure if I understand what it needs there.
In the textedit example it uses textEdit = new QTextEdit(this); to initialize a value which is later used in the PrintPreview. But in my case what do I initialize?
Any help is appreciated.
Thanks,
Pericles
Added after 30 minutes:
I added the following code in the printPreview function instead of ui->editor->print(printer)
// create painter for drawing print page
QPainter painter( printer );
// you can do formatting here...
QFont font;
font.setPointSize(18);
painter.setFont(font);
for (int i = 0; i < 3; i++) {
painter.drawText(10, 10, QString("page number: %1").arg(i));
// move to next page
if (i != 2) printer->newPage();
}
It opens the print preview dialog box but nothing is showing up in it.
Do I need to specify anywhere what to show?
Pericles
Added after 46 minutes:
Just found out that I needed to do widget->render();
Works now.
Thanks,
Pericles
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.