Search code examples
qtqt5qwidgetqpainterqprinter

Qt - Print widgets in specific layout


In my project I have some own widgets. When I click on a toolbar-button to print, I want to print the widgets in a specific layout (landscape-orientation).

I tried it with a new QWidget with a layout, and in this layout add my widgets. But when I do this, my widget disappear from my mainwindow.

How can I print my widget without disappearing and my own layout?


Solution

  • I had asked something similar - Printing complex widgets

    and basically ended up in some design, where I set up an invisible copy of the whole widget and caused it to resize on the best size for the print job - take portrait and landscape printing into consideration!

    I had to add code to paint- and resize- related methods of my custom widgets, where depending if I was printing or painting to screen, I modified palettes, font sizes, style sheets etc. Modifiying palettes might be necessary if your printer is black/white only. Or if your application has a dark background, you might want to flip colours.

    This was quite a tedious job, but you will notice, that customers often don't want a screen hardcopy but something better.