Debian Codegraph @

tests/manual/qtbug-52641/main.cpp

raw
1 // Copyright (C) 2016 Kai Pastor
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QApplication>
5 #include <QFileDialog>
6 #include <QPainter>
7 #include <QPainterPath>
8 #include <QPdfWriter>
9
10 int main(int argc, char *argv[])
11 {
12 QApplication a(argc, argv);
13
14 QString filepath = QFileDialog::getSaveFileName(nullptr, "Save File", "",
15 "PDF files (*.pdf)");
16 if (filepath.isEmpty())
17 return 1;
18 QPdfWriter writer(filepath);
19 writer.setPageSize(QPageSize(QPageSize::A4));
20 writer.setResolution(300);
21
22 QPainterPath path;
23 path.moveTo(0,0);
24 path.lineTo(1000,0);
25 path.lineTo(1000,1000);
26 path.lineTo(0,800);
27 path.lineTo(500,100);
28 path.lineTo(800,900);
29 path.lineTo(300,600);
30
31 QPen pen;
32 pen.setWidth(30);
33 pen.setJoinStyle(Qt::MiterJoin);
34
35 // The black path on the first page must always be visible in the PDF viewer.
36 QPainter p(&writer);
37 pen.setMiterLimit(6.0);
38 p.setPen(pen);
39 p.drawPath(path);
40
41 // If a miter limit below 1.0 is written to the PDF,
42 // broken PDF viewers may not show the red path on the second page.
43 writer.newPage();
44 pen.setMiterLimit(0.6);
45 pen.setColor(Qt::red);
46 p.setPen(pen);
47 p.drawPath(path);
48
49 p.end();
50 return 0;
51 }