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. 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) As you can see, it's "blurry" and not neat. I tried to play on the renderHint, on the resolution, but I don't find something quite good. Thing is the result doesn't have a good quality. The QPdfPageRenderer class manages a queue that collects all render requests. The QPdfDocument class loads a PDF document and renders pages from it according to the options provided by the QPdfDocumentRenderOptions class. 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). The Qt PDF module contains classes and functions for rendering PDF documents. QPixmap screenshotPDF = contenu->QWidget::grab() tRenderHint(QPainter::SmoothPixmapTransform) 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)") ![]() This QDialog contains a scrollArea, defined at the centralWidget. In practice, it summarize all the inputs and outputs, in a QDialog. In this GUI I have incorporated an "overview". 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). 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. In order to do so, uncomment the following line. I'll ask a follow up question about that.I have some problems using QPdfWriter and QPainter to print a part of a QDialog. QT + core gui greaterThan(QTMAJORVERSION, 4): QT + widgets CONFIG + c++11 You can make your code fail to compile if it uses deprecated APIs. The thing I still don't like about this approach is that a page break can be added between the heading and the diagram. Painter.drawArc((rect.width() - diameter) // 2,ĭtPageSize(QSizeF(pdf.width(), pdf.height()))ĭoc_layout.registerHandler(DIAGRAM_TEXT_FORMAT, diagram_handler)ĭiagram_tObjectType(DIAGRAM_TEXT_FORMAT)ĭiagram_tProperty(DIAGRAM_DATA, f'Message in a circle')Ĭursor.insertText(OBJECT_REPLACEMENT, diagram_format) But try out the Text Edit example (in widgets\richtext) - it contains a PDF export. # noinspection PyPep8Naming,PyShadowingBuiltins i'm trying to create a PDF from Qt Creator. Here's my example from the question converted to use QPyTextObject: from PySide6.QtCore import QSizeF, QRectFįrom PySide6.QtGui import (QPdfWriter, QPainter, QPageSize, QTextDocument, Qt, QPyTextObject, QTextFormat, QTextCursor,ĭIAGRAM_TEXT_FORMAT = QTextFormat.UserObject + 1 It would be useful if I needed to spread over multiple pages, I think. ![]() This TextObject example gives a good introduction. Painter.window().width() // 2, painter.window().height() // 2, "Bar"ĭef print_document(painter: QPainter, pdf: QPdfWriter):ĭocument.documentLayout().setPaintDevice(pdf)Īlthough I ended up using eyllanesc's answer of switching from document.print_() to document.drawContents(), I also experimented with QTextCursor and QPyTextObject. from PySide6.QtGui import QPdfWriter, QPainter, QPageSize, QTextDocument, Qtĭef draw_diagram(painter: QPainter, pdf: QPdfWriter): A possible solution is to use the same QPainter and instead of the print method you should use drawContents, you will also have to handle the paging manually. The problem is that every time a QPainter is set then the QPdfWriter is reset. How can I combine drawings with a text document? Is QTextCursor helpful? Ideally, I'd like text and drawing on the same page, but this code tries to keep them separate so they don't overwrite each other. Painter.drawText(painter.window().width()//2, ![]() Painter.drawArc(painter.window().width()//4, # Whichever of these goes second, overwrites the first. from PySide6.QtGui import QPdfWriter, QPainter, QPageSize, QTextDocument, Qtįrom PySide6.QtWidgets import QApplication However, when I tried to do that, they each restart the document, wiping out the other's content. In another question, I learned about QTextDocument, and I was told that you can use a QPainter and a QTextDocument on the same page of a PDF.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |