Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a Qt dialog or window?

How do I get Qt to print a complete dialog or window? I could dump the window contents with an external program like xwd and print that, but I would prefer to do it all with Qt.

like image 514
PiedPiper Avatar asked Dec 05 '22 06:12

PiedPiper


1 Answers

While you can use grabWidget to get the pixmap representation of the dialog, essentially you will be printing the pixels of the pixmap, i.e. the dialog is rasterized a the screen resolution and then scaled to the printer resolution. This may or may not result in some artifacts.

Another way to do it is by using QWidget::render() function that takes a paint device. This way, you can pass your printer as the paint device. The dialog is now "drawn" onto the printer with the the printer's resolution.

like image 117
Ariya Hidayat Avatar answered Dec 08 '22 00:12

Ariya Hidayat