You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qt 6.3.1中QTextDocument需三次回车才新建段落的问题咨询

Qt 6.3.1中QTextDocument段落插入异常问题
  • 在Qt 6.3.1版本中,当用空行分隔的两个段落填充QTextDocument后,若要在两段之间插入一个带空行的新段落,需要按下三次Enter键,而非预期的两次。
  • 该问题在Qt 5.15版本中无法复现,怀疑是Qt 6.3.1的回归bug。

可复现代码

#include <QTextEdit>
#include <QApplication>
#include <QTextDocument>

void fillTextDocument(QTextDocument *doc, const QString &text)
{
    QTextCursor c(doc);

    c.movePosition(QTextCursor::End);

    QTextCharFormat fmt = c.charFormat();
    QTextBlockFormat b = c.blockFormat();

    fmt.setFontWeight(QFont::Normal);
    fmt.setFontItalic(false);
    fmt.setFontUnderline(false);

    fmt.setAnchor(false);
    fmt.setAnchorHref(QString());
    fmt.setForeground(QBrush(Qt::black));

    b.setAlignment(Qt::AlignLeft);

    QFont f = fmt.font();
    f.setPixelSize(15);
    fmt.setFont(f);

    c.setCharFormat(fmt);

    c.setBlockFormat(b);

    c.insertText(text);

    c.movePosition(QTextCursor::End);

    doc->clearUndoRedoStacks();
}

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QTextEdit e;
    fillTextDocument(e.document(), QStringLiteral("Hello\n\nHello"));
    e.resize(600, 400);
    e.show();

    return QApplication::exec();
}

请问这是我的操作有误,还是Qt的问题?

内容的提问来源于stack exchange,提问作者Igor Mironchik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 19:36:18