I have a complex widget with tons of different subwidgets, e.g. subclasses of QLabel. I want to print this widget, but obviously I do not want to print the background, I want to print with differing text colors or have the style of frames slightly modified.
As I do not really want to iterate through all subwidgets with a special "print" function, which I would need to attach to all widgets (how to add "print" to a QLabel?), I would like to use paintEvent.
If I have a hierarchy MyWidget -> derived from -> some QWidget, I would like to insert a sublayer MyWidget -> MyPrintWidget -> some QWidget, where myPrintWidget::paintEvent would check, if the current print is going to the screen (thus call QWidget::paintEvent), else if we are printing to the printer, call some function MyPrintWidget::drawWidget instead.
- Is this the right way to print-enable a widget?
- How can I figure out in paintEvent, that I'm printing to a printer instead of the screen?
- Is there a good example of printing complex widgets?