Important: Please read the Qt Code of Conduct -

How to print contents from stackedWidget with QPrinter

  • Hi, is it possible to print contents from two multiple stackedWidget pages using QPrinter. And if it's possible how do I go about it, any assistance is appreciated. This is my first time using QPrinter.

  • @LT-K101 Please clarify, you mean the content/values held in the widgets of the stack or more like a screenshot of it?

  • @artwaw yes please, I have a stackedWiget with (3 pages) and I would like to print all the contents and values of the stackedWiget altogether on an A4 using a printer.

  • @LT-K101 You just have to iterate over the widgets and do it mostly by hand I am afraid, and construct everything.

    if you fancy nice output you can create rich text document (iterating over values and adding html subset elements to one QString, then using QTextDocument::setHtml() with said QString so it is all nicely laid down on pages and QTextDocument::print() to actually print it) or if not, any example of QPrinter printing regular text will do.

    Rich Text Processing overview is here

    But there is no explicit way to gather the data automatically from stacked widget I am afraid.

  • @LT-K101
    You can go down @artwaw's way of creating a document from your data and printing that. But it's quite a lot of work.

    Are you instead just wanting to print/paint a "screenshot" of each page (just like it looks on screen) on the printer?

Log in to reply