所以我需要pdf格式的QtextFrame中的边框(QPrinter的pdf输出)。以下是我使用的代码
#include <QPainter>
#include <QTextFrameFormat>
#include <QTextCursor>
#include <QTextFrame>
#include <QTextEdit>
#include <QPrinter>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QTextDocument doc;
QPixmap map(1024, 1024);
map.fill(Qt::white);
QPainter p;
p.begin(&map);
p.fillRect(QRect(0,0, 4, map.height()), QBrush(Qt::red));
p.end();
QTextFrameFormat frameFormat;
QBrush bruh(map);
bruh.setColor(Qt::transparent);
frameFormat.setBackground(bruh);
frameFormat.setPadding(6);
auto cur = new QTextCursor(&doc);
auto frame = cur->insertFrame(frameFormat);
auto curf = new QTextCursor(frame);
curf->insertText("Hello this is qt program!");
QPrinter pdf;
pdf.setOutputFileName("E:\\test.pdf");
pdf.setOutputFormat(QPrinter::PdfFormat);
doc.print(&pdf);
QTextEdit edt;
edt.setDocument(&doc);
edt.show();
return a.exec();
}