Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QPrintDialog / QPrintPreviewWidget Interaction



  • Hello!

    Does QPrintDialog interact with a QPrintPreviewWidget?

    I have a QPrintPreviewWidget which draws everything I need it to draw across a few pages. Before printing, I launch a QPrintDialog and pass on QPrinter object. And I then run QPrintPreivewWidget::print().

    I assumed, QPrintDialog changes the settings in the QPrinter object (like page from/to) so the print function would take these changed into effect, but it seems the settings of QPrintPreviewWidget are independent? And if it is, do I have to manually only print the selected pages or is there an automatic way to specify the range?

    Thank you!


  • Lifetime Qt Champion

    @Adam-Crowe said in QPrintDialog / QPrintPreviewWidget Interaction:

    I launch a QPrintDialog and pass on QPrinter object. And I then run QPrintPreivewWidget::print().

    Do you pass the same QPrint object also to QPrintPreivewWidget?



  • Hi @jsulm,

    This whole question started when I tried to set the to/from page range for printing. The only other time I did this sort of printing was in C# on .Net where the print dialog automatically prints the pages you ask it to print. When QPrintDialog didn't do that, I started wondering how much it actually controls.

    I couldn't find much online about this. All the examples online print text directly from a QTextEdit or similar widget which makes controlling pages very straightforward, but I'm drawing something quite complicated so it wasn't as straightforward. It would have been very convenient to draw everything and let QPrintDialog send the relevant pages to the printer like .Net does.

    After some experimentation, I figured out that the QPrinterDialog does change the settings of the QPrinter object you pass to it but that's it. It doesn't control the printing process at all. I had to implement that functionality myself.

    Please note that I only use QPrintPreviewWidget to show the preview on the screen. I don't use it to print because it prints the whole preview no matter what! Instead I render the same drawing again directly to the QPrinter.

    It's a bit convoluted but I suppose printing is :-/


Log in to reply