Results 1 to 5 of 5

Thread: QPrintPreviewDialog help

  1. #1

    Default QPrintPreviewDialog help

    Hello there,
    I know there are a lot of topics about QPrintPreviewDialog issues, I read a lot of them but it didn't help me so here I am. I need some explanations because I don't understand how it works.
    I've got two QPushButtons that will call either the print preview or the print itself.
    Here's my code so far:
    Qt Code:
    1. //My printPreview slot
    2. QPrinter printer(QPrinter::HighResolution);
    3. QPrintPreviewDialog preview(&printer, this);
    4. preview.setWindowFlags ( Qt::Window );
    5. preview.setWindowTitle("Aperçu avant impression");
    6. connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(Impression(QPrinter *))); //Impression is my print slot. When is paintRequested emitted exactly? I read the documentation but didn't understand....
    7. preview.exec();
    8.  
    9.  
    10. //My Print slot
    11. QPainter painter;
    12. painter.begin(p); //p is my QPrinter
    13. double xscale = p->pageRect().width()/double(ui.Onglets->width());
    14. double yscale = p->pageRect().height()/double(ui.Onglets->height());
    15. double scale = qMin(xscale, yscale);
    16. painter.translate(p->paperRect().x() + p->pageRect().width()/2, p->paperRect().y() + p->pageRect().height()/2); // to put my widget in the center of my page
    17. painter.scale(scale, scale);
    18. painter.translate(-width()/2, -height()/2);
    19.  
    20. ui.Onglets->render(&painter); //Onglets is a QTabWidget
    To copy to clipboard, switch view to plain text mode 

    So far only a part of my window shows up in my preview dialog. This problem comes from my print slot or the print preview one?
    Could you please explain to me how it works exactly?
    Thanks in advance for your answers.
    Last edited by Yaoming; 25th February 2014 at 17:06.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPrintPreviewDialog help

    The problem is in your Impression(QPrinter *) slot. You determine the scale based on the width() and height() of ui.Onglets. When you translate to the centre, scale, and translate back using the different width() and height() of the containing widget.

  3. #3

    Default Re: QPrintPreviewDialog help

    Thanks for your answer, I'll work on that.
    Could you explain to me how this all thing works please? I hate working on something I don't fully understand... When is the paintRequested signal emitted?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPrintPreviewDialog help

    The preview dialog emits paintRequested() when it needs to draw the previewed content. It does this at once immediately after the dialog is shown, but it may emit the signal again if the user does things like select another printer, page size, or margins using the controls in the dialog. Each time the signal is emitted the preview area starts empty and you should render the entire document onto the supplied printer.

  5. #5

    Default Re: QPrintPreviewDialog help

    Thanks for your help. I'm using the print function instead of my painter and it works just fine.
    Attached Images Attached Images
    Last edited by Yaoming; 28th February 2014 at 14:40.

Similar Threads

  1. QPrintPreviewDialog linux
    By davidovv in forum Qt Programming
    Replies: 0
    Last Post: 12th February 2013, 00:10
  2. Pratical example of QPrintPreviewDialog
    By vcp in forum Qt Programming
    Replies: 5
    Last Post: 24th July 2012, 16:24
  3. QPrintPreviewDialog.
    By cydside in forum Qt Programming
    Replies: 2
    Last Post: 19th June 2009, 17:31
  4. QPrintPreviewDialog icons
    By quipu5 in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2009, 13:36
  5. 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.