0

我想在 QTextDocument 中的文本周围有一个唯一的左边框
我认为为此所需的 css 将是

<div style='
  border-left: 6px solid red;
  background-color: lightgrey;
'> Hello World </div>

但是可以说我有这个qt代码

#include <QApplication>
#include <QWidget>
#include <QHBoxLayout>
#include <QTextEdit>

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    QWidget *widget = new QWidget();
    auto l = new QHBoxLayout(widget);
    widget->setLayout(l);
    QTextEdit *e = new QTextEdit(widget), *t = new QTextEdit(widget);
    l->addWidget(e);
    l->addWidget(t);

    QObject::connect(e, &QTextEdit::textChanged, [=]() {
        t->setHtml(e->toPlainText());
    });

    widget->show();
}

现在如果输入 html 我得到了这个输出

图像

但正确和必需的输出应该是 - 在此处输入图像描述

我想要上面的输出,有什么我遗漏的吗?

4

1 回答 1

1

不幸的是,Qt 富文本QTextDocument不支持除了表格之外的任何东西的边框。即便如此,它同时也是所有边界,而不是个别的边。 https://doc.qt.io/qt-5/richtext-html-subset.html#css-properties

更新:这让我想起了 1996 年为 MSIE 编写 HTML,但是嘿,(几乎)总是有一种方法......(这里唯一的 CSS 实际上是可选的,“必需的输出”图像没有填充 :) .

在此处输入图像描述

<!-- with width=100% the table extends all the way to the right margin -->
<table cellspacing=0 width='100%'>
<tr>
  <td width=6 bgcolor='red'/>
  <td bgcolor='lightgrey' 
      style='padding: 0 4px;'
    >Hello World</td>
</tr>
</table>
于 2019-10-15T15:52:29.513 回答