You are on page 1of 2

7/9/2021 Qt, printing a QDialog in PDF format, quality issues - Stack Overflow

Qt, printing a QDialog in PDF format, quality issues


Asked
3 years, 3 months ago Active
3 years, 3 months ago Viewed
217 times

I have some problems using QPdfWriter and QPainter to print a part of a QDialog.

1 To contextualize a bit, I'm working as Engineer in a Telemetry/LiDAR company, and for


internal use I have developed a GUI for easily compare/simulate our systems. I have no
computer formation so I developed it only after following some Qt tutorials etc (I like coding in
general, but I mean I am not that goood at it).

In this GUI I have incorporated an "overview". In practice, it summarize all the inputs and
outputs, in a QDialog. This QDialog contains a scrollArea, defined at the centralWidget.
(screen right there : https://imgur.com/a/iiCGnaX )

So my researches make me use this kind of coding to grab the scrollArea, and to print it in
PDF :

QString filePath=QFileDialog::getSaveFileName(this, "System summary",path,"PDF


files (*.pdf)");

QPdfWriter pdfWriter(filePath);

pdfWriter.setResolution(100);

QPainter painter;

painter.begin(&pdfWriter);

painter.setRenderHint(QPainter::SmoothPixmapTransform);

QPixmap screenshotPDF = contenu->QWidget::grab();

painter.drawPixmap(0,0,screenshotPDF);

painter.end();

In case of, the content of the screen area is completely manually made (It has the dimension
of an A4 paper, and I put the QGroupBox without layout).

Thing is the result doesn't have a good quality. I tried to play on the renderHint, on the
resolution, but I don't find something quite good.
screen here : https://imgur.com/a/Gh3LHPM.
As you can see, it's "blurry" and not neat.

I guess I'm doing something wrong, but all that I try didn't work really well (for example, if I just
change the "setResolution" line to N*100, I end up with something N time too small/High)

That's the first time I post here, I hope my question is appropriate, also I wanted to thank you
for this forum which help a lot the neophyte I am.

Imra'

qt pdf printing qprinter

Share Improve this question edited May 23 '18 at 7:15 asked May 22 '18 at 13:10
Join Stack
FollowOverflow to learn, share knowledge, and build your career. Imra Sign up
11 2
https://stackoverflow.com/questions/50468588/qt-printing-a-qdialog-in-pdf-format-quality-issues 1/2
7/9/2021 Qt, printing a QDialog in PDF format, quality issues - Stack Overflow

¿No encuentras la respuesta? Pregunta en Stack Overflow en español.

Join Stack Overflow to learn, share knowledge, and build your career. Sign up

https://stackoverflow.com/questions/50468588/qt-printing-a-qdialog-in-pdf-format-quality-issues 2/2

You might also like