[Solved] QPrintPreviewDialog paint request purpose



  • Qt 4.8.5. I use QPrintPreviewDialog like this:

    @
    QPrintPreviewDialog PreviewDialog(/some arguments.../);
    connect(
    &PreviewDialog,
    SIGNAL(paintRequested(QPrinter*)),
    SLOT(onPaintRequest(QPrinter*))
    );
    @

    How to figure out what is going on inside the onPaintRequest - actual printing or print preview generation? Maybe I must use two different onPaintRequest procedures somehow?

    @
    void onPaintRequest(QPrinter* pPrinter)
    {
    // what is going on?
    }
    @


  • Moderators

    the "docs stating":http://qt-project.org/doc/qt-4.8/qprintpreviewdialog.html#details it very clear.
    The signal is emitted whenevery a preview needs to be re-/drawn. You can use the same painting mechanism you would use for actual printing.
    If your printing is very complex you may want to cache your printing for preview.



  • Sorry, I didn't say enough about my goal. I need to implement different behavior for:

    • case 1 - actual printing
    • case 2 - print preview generation

    But I have only one onPaintRequest handler for both cases because QPrintPreviewDialog have only 1 signal (paintRequested) for both cases.

    @
    void onPaintRequest(QPrinter* pPrinter)
    {
    bool PreviewGenerating = ? // how?

    if (PriviewGenerating)
        DoSomething();
    else // actual printing
        DoSomethingElse();
    

    }
    @


  • Moderators

    ok got ya.
    The problem is that there is no clean way via the QPrinter API.
    On a first glance i only found this kinda hacky/unclean way:
    Save the pointer of pPrinter->paintEngine() as your preview indicator. This won't change for following preview requests.
    For the actual printing another paintEngine object will be created and thus it is different.
    But as said its a rather unclean/hackish way. Maybe someone else has a better idea?



  • Thank you, raven-worx, your solution is enough for me.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.