gpt4 book ai didi

c++ - 文本文档中只有左边框

转载 作者:行者123 更新时间:2023-11-30 04:43:06 26 4
gpt4 key购买 nike

我试图在 QTextDocument 中只绘制左边框。由于 afaik QTextFrame 不支持选择性边框,因此我尝试为文本框分配纹理画笔。像下面这样的东西 -

#include <QPainter>
#include <QTextFrameFormat>
#include <QTextCursor>
#include <QTextFrame>
#include <QTextEdit>

int main(int argc, char *argv[]) {
QApplication a(argc, argv);

QTextDocument doc;
QPixmap map(1024, 1024);
QPainter p;
p.begin(&map);
p.setBackground(QBrush(Qt::transparent));
p.drawRect(QRect(0,0, 4, map.height()));
p.end();

QTextFrameFormat frameFormat;
QBrush bruh(map);
bruh.setColor(Qt::transparent);
frameFormat.setBackground(bruh);
auto cur = new QTextCursor(&doc);
auto frame = cur->insertFrame(frameFormat);
auto curf = new QTextCursor(frame);
curf->insertText("Hello this is qt program!");

QTextEdit e;
e.setDocument(&doc);
e.show();

return a.exec();
}

但是即使背景设置为透明,这也会打印黑色背景(我需要一个只有红色边框的透明背景)。
我不知道出了什么问题。另外,是否有任何其他方法可以让 QTextFrame 只有左边框?
enter image description here

最佳答案

试试这个:

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();

关于c++ - 文本文档中只有左边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58461469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com