如何将一个QTextDocument部分复制到另一个QTextDocument的所有格式
How to partially copy one QTextDocument to another with all of it's formatting
我需要制作一个非常大的QTextDocument的预览版本副本(在富文本模式下(。所以,我需要一些类似于它的clone()
函数的东西,但能够指定限制。即clone (int maxChars)
。正如我从clone()
源代码中了解到的,它只是将一个文档作为单个QTextDocumentFragment复制到另一个文档。所以,我不能以我需要的方式修改这个过程。
有什么想法可以实现吗?
您可能想要执行以下操作:
- 以
QTextDocument
为父对象创建QTextCursor
- 致电
cursor.movePosition(QTextCursor::Start)
。这将把光标的位置设置为文档的开头 - 调用
cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor, n)
,其中n
是您希望在选择中使用的单词数量 - 致电
cursor.selection()
。此方法将返回选定的QTextDocumentFragment
如果使用富文本(通过html标记指定(,请执行以下操作:
// assuming some QTextDocument named 'source', return rich text as html QString object
QString html = source.toHtml();
// pass substring to new QTextDocument instance
QTextDocument dest(html.mid(startChar,endChar));
其中startChar和endChar是源QTextDocument的html字符串的整数索引。
相关文章:
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 使用strcpy将char数组的元素复制到另一个数组
- 是否可以初始化不可复制类型的成员变量(或基类)
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 复制列表初始化的隐式转换的等级是多少
- 当从函数参数中的临时值调用复制构造函数时
- 有可能在Armadillo中复制MATLAB circshift方法吗
- 复制几乎为空的数组的最快方法
- 以下示例中如何避免代码复制?C++/库达
- 如果有一个模板构造函数只有一个泛型参数,为什么我必须有一个复制构造函数
- 为什么需要复制构造函数,在哪些情况下它们非常有用
- 不能将复制初始化与隐式转换的多个步骤一起使用
- 当有分配器意识的容器被复制/移动时,反弹分配器是否被复制/移走
- 为什么复制而不是移动数据元素?
- 文件系统:复制功能的速度秘诀是什么
- 使用仅使用一次的变量调用的复制构造函数.这可能是通过调用move构造函数进行编译器优化的情况吗
- 通过QT将(rtf)表复制到剪贴板(或:将QTextDocument写入剪贴板)
- 如何将一个QTextDocument部分复制到另一个QTextDocument的所有格式