使用可选文本将QWidget渲染为PDF

问题描述

假设^-?[1-9]*\.?\d+$作为其他小部件的容器。此容器中的窗口小部件是布局为QWidget的窗口小部件,应显示QVBoxLayout的两列。之后,出现了一个新的小部件,它是QLabel

我现在想将上述小部件呈现为具有可选文本的PDF文件。现在,我用{p>设置了QTableView和相应的QPrinter

QPainter

现在我使用渲染小部件

QPrinter* printer = new QPrinter(selectedPrinterInfo,QPrinter::ScreenResolution);
printer->setPageSize(QPageSize(QPageSize::A4));
printer->setorientation(QPrinter::Portrait);
printer->setFullPage(true);
printer->setPageSize(QPrinter::A4);
printer->setoutputFormat(QPrinter::PdfFormat);
printer->setPageMargins(QMarginsF(15,15,15),QPageLayout::Unit::Millimeter);
printer->setoutputFileName(fileName);
printer->setResolution(300);

QPainter painter(printer);

这将创建一个质量很好的PDF,但是它只是带有pdf文件的图像。文本不可选择。我选择它的方法是首先将myWidget->render(&painter); 渲染到myWidget,然后将其重播到QPicture

QPainter

这将创建一个具有可选文本的PDF。我的这种方法QPicture picture; myWidget->render(&picture); painter.drawPicture(0,picture); 遇到的问题是,正确显示此表存在严重问题。例如。我将QPicture设置为AlternatingRowColors,现在行颜色与网格线重叠。因此,有没有什么方法可以直接将true作为PDF来渲染QWidget,也可以使用任何其他方法而不使用QPainter

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...