Printing complex widgets in Qt
Posted
by Jens
on Stack Overflow
See other posts from Stack Overflow
or by Jens
Published on 2010-06-10T18:32:51Z
Indexed on
2010/06/10
23:42 UTC
Read the original article
Hit count: 230
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?
© Stack Overflow or respective owner