Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QPrintPreviewDialog paint request purpose
Forum Updated to NodeBB v4.3 + New Features

[Solved] QPrintPreviewDialog paint request purpose

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    YuriQ
    wrote on last edited by
    #1

    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?
    }
    @

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        YuriQ
        wrote on last edited by
        #3

        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();
        

        }
        @

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          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?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            YuriQ
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved