[英]Print a textEdit in Qt
How can I print the text available in a textEdit
using Qt creator (C++)? 如何使用Qt Creator(C ++)打印textEdit
可用的文本? Please help me with this. 请帮我解决一下这个。 I created a note pad using a textEdit
. 我使用textEdit
创建了一个textEdit
。 Now I want to print the note pad content. 现在我要打印记事本内容。 That mean the text typed in textEdit
. 这意味着在textEdit
键入的文本。 So please help me. 所以请帮帮我。
please mention header files that I need to include as well. 请提及我也需要包含的头文件。
Here is something I tried previous. 这是我之前尝试过的东西。 but it's not working. 但它不起作用。 so please help me with this. 所以请帮我
void MainWindow::on_action_Print_triggered()
{
QString textFromField = ui->txtEdit->toPlainText();
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFileName("print.ps");
QPainter painter;
painter.begin(&printer);
printer.newPage();
painter.end();
}
QTextEdit
already has method which allows you print it's content, so you don't need QPainter
. QTextEdit
已经有允许您打印其内容的方法,因此您不需要QPainter
。 Use this (I printed pdf
as example): 使用这个(我以pdf
打印为例):
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("outputt.pdf");
ui->textEdit->print(&printer);
And of course you need 当然需要
#include <QPrinter>
but I think that it is already added in your project. 但我认为它已添加到您的项目中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.