<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Using Qt 5.15 and PySide2, I am working on a project that requires me to produce a PDF output. My process so far is to create a QWidget containing the content I want, render it to a QPicture (so it won’t be rasterized upon “printing”), then create a PDF QPrinter and use the painter.drawPicture() function to “print” the widget into a PDF.<div class=""><br class=""></div><div class="">This works well, giving me a high-quality vectorized PDF output, with one exception: any item that is filled with a gradient. When printing to PDF, the gradient always comes out as solid white. With some digging, I determined that this is even the case when doing nothing but a simple painter.fillRect() with a gradient.</div><div class=""><br class=""></div><div class="">Is there any “fix” for this? Thanks.</div><div class=""><br class=""></div><div class="">If it helps, here is some simple code that reproduces the issue:</div><div class=""><br class=""></div><div class=""><div class="">from PySide2.QtWidgets import QApplication</div><div class="">from PySide2.QtGui import QPainter, QPageSize, QLinearGradient</div><div class="">from PySide2.QtPrintSupport import QPrinter</div><div class="">from PySide2.QtCore import QSize, QRect, Qt</div><div class=""><br class=""></div><div class="">app = QApplication()</div><div class=""><br class=""></div><div class="">gradient_rect = QRect(0, 0, 500, 25)</div><div class="">gradient = QLinearGradient(0, 0, 1, 0)</div><div class="">gradient.setColorAt(0, Qt.blue)</div><div class="">gradient.setColorAt(1, Qt.red)</div><div class=""><br class=""></div><div class="">page_size = QPageSize(QSize(500, 25), matchPolicy = QPageSize.ExactMatch)</div><div class="">printer = QPrinter()</div><div class="">printer.setOutputFormat(QPrinter.PdfFormat)</div><div class="">printer.setPageSize(page_size)</div><div class="">printer.setOutputFileName('/tmp/testPDFGradient.pdf')</div><div class=""><br class=""></div><div class="">painter = QPainter(printer)</div><div class="">painter.fillRect(gradient_rect, gradient)</div><div class="">painter.end()</div></div><div class=""><br class=""><div class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">---</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">Israel Brewster<br class="">Software Engineer<br class="">Alaska Volcano Observatory <br class="">Geophysical Institute - UAF <br class="">2156 Koyukuk Drive <br class="">Fairbanks AK 99775-7320</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">Work: 907-474-5172<br class="">cell:  907-328-9145</div></div>
</div>

<br class=""></div></body></html>