Results 1 to 6 of 6

Thread: Pratical example of QPrintPreviewDialog

  1. #1
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Pratical example of QPrintPreviewDialog

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Pratical example of QPrintPreviewDialog

    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?

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Pratical example of QPrintPreviewDialog

    Quote Originally Posted by vcp View Post
    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.co...o/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....?content=80650

    Qt Code:
    1. void TextEdit::filePrintPreview()
    2. {
    3. #ifndef QT_NO_PRINTER
    4. QPrinter printer(QPrinter::HighResolution);
    5. QPrintPreviewDialog preview(&printer, this);
    6. preview.setWindowFlags ( Qt::Window );
    7. connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *)));
    8. preview.exec();
    9. #endif
    10. }
    11.  
    12. void TextEdit::printPreview(QPrinter *printer)
    13. {
    14. #ifndef QT_NO_PRINTER
    15. textEdit->print(printer);
    16. #endif
    17. }
    To copy to clipboard, switch view to plain text mode 

    IMO: if you like to build static QPrintPreviewDialog append his icon

  4. #4
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Pratical example of QPrintPreviewDialog

    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.

  5. #5
    Join Date
    Apr 2010
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Pratical example of QPrintPreviewDialog

    hi.
    why the printer in this function:
    Qt Code:
    1. void dlg_account::on_btn_print_clicked()
    2. {
    3. QPrinter printer(QPrinter::HighResolution);
    4. printer.setFullPage( true );
    5. QPrintPreviewDialog preview(&printer, this);
    6. preview.setWindowFlags ( Qt::Window );
    7. connect(&preview, SIGNAL(paintRequested(QPrinter* )), SLOT(print(QPrinter* )));
    8. preview.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 
    isnt recognised in the:
    Qt Code:
    1. void dlg_account::print( QPrinter* printer)
    2. {
    3. QPainter *painter=new QPainter(printer);
    4. QRect paper = printer->pageRect();
    5. painter->setPen(Qt::black);
    6. painter->setFont(QFont("Sans",14,0,0));
    7. painter->drawText(QRect(0,0,100,100),Qt::AlignLeft||Qt::AlignTop,"page1");
    8. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Pratical example of QPrintPreviewDialog

    I am having difficulties with implementing the QPrintPreviewDialog.

    I included this code in the function that calls the printing:
    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    2. QPrintPreviewDialog ppd(&printer,this,Qt::Window);
    3. connect(&ppd, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *)));
    4. ppd.exec();
    To copy to clipboard, switch view to plain text mode 

    And I also added this function at the end:
    Qt Code:
    1. void PackageDialog::printPreview( QPrinter* printer)
    2. {
    3. ui->editor->print(printer);
    4. }
    To copy to clipboard, switch view to plain text mode 

    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)
    Qt Code:
    1. // create painter for drawing print page
    2. QPainter painter( printer );
    3. // you can do formatting here...
    4. QFont font;
    5. font.setPointSize(18);
    6. painter.setFont(font);
    7.  
    8. for (int i = 0; i < 3; i++) {
    9.  
    10. painter.drawText(10, 10, QString("page number: %1").arg(i));
    11. // move to next page
    12. if (i != 2) printer->newPage();
    13. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by pcheng; 24th July 2012 at 16:24.

Similar Threads

  1. Qt 4.4.0 Problem with QPrintPreviewDialog
    By ad5xj in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2008, 14:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.