Unsolved Print the content of QTextEdit
-
Hi,
I am developing a text editor with Python and Qt.
The text files are loaded into QTextEdit.Question:
How can I print the content of QTextEdit -
Hi,
Since there's a print primitive in python, are you referring to that or the use of a physical printer ?
-
@PythonQTMarlem said in Print the content of QTextEdit:
QTextEdit
Yes, I would like to print the content of QTextEdit on a hardware printer connected to the laptop.
-
So the print support module is what you are looking for.
-
I tried this, but the program crashes:
printDialog = QPrintDialog if (printDialog.exec () == QDialog.Accepted): self.texteditor.print (printDialog.printer ())
-
What exact error are you getting ?
-
the programm stoppt with:
Process finished with exit code -1073740791 (0xC0000409)
-
@PythonQTMarlem
If you haven't already verified this: start by breaking your code down into individual lines so that we can be sure where exactly the crash is happening, e.g.printDialog = QPrintDialog print("Got here 1") result = printDialog.exec () print("Got here 2") if (result == QDialog.Accepted): print("Got here 3") result = printDialog.printer () print("Got here 4") self.texteditor.print (result) print("Got here 5")
Otherwise, what else have you checked printing-wise from Python/Qt? Is it just an issue from
QTextEdit.print()
(doubtful), or does the whole of printing/printDialog.printer ()
not work? It is possible that crash comes from Windows, e.g. the print spooler, and has nothing to do with Qt. -
@JonB said in Print the content of QTextEdit:
printDialog = QPrintDialog
print("Got here 1")
result = printDialog.exec ()
print("Got here 2")
if (result == QDialog.Accepted):
print("Got here 3")
result = printDialog.printer ()
print("Got here 4")
self.texteditor.print (result)
print("Got here 5")thank you.
it crashes after this:
result = printDialog.exec() -
the following code i found in web:
def dateidruckentest1(): self.statusBar().showMessage("Datei wird gedruckt") self.print_device = QtPrintSupport.QPrinter() def files(self, action): if action.text() == "Print": print_dialog = QtPrintSupport.QPrintDialog(self.print_device) if print_dialog.exec_() == QtWidgets.QDialog.Accepted: self.text_edit.print_(print_dialog.printer()) if action.text() == "Print Preview": print_dialog = QtPrintSupport.QPrintPreviewDialog(self.print_device) print_dialog.setWindowTitle("Print Preview") print_dialog.paintRequested.connect(self.texteditor.print_) print_dialog.exec_()
when i try it, nothing happens. no message, no error message, nothing.
-
@PythonQTMarlem said in Print the content of QTextEdit:
it crashes after this:
result = printDialog.exec()I presume you mean you do not see the print dialog come up (or do you mean, it comes up, you click something, then it crashes upon return)? I don't know what the reason/solution is, but this tells you the issue lies in even presenting a print dialog, not in actually attempting to do any printing.
-
What version of PyQt5/PySide2 are you using ?
How did you install it ?