0

我正在编写一个程序,我必须编写一个打开 *.odt 文件的代码。我的想法是从 *.odt 文档中提取 content.xml 文件,并将该 xml 文件中的文本设置为我的 QTextEdit 对象。我做了这个操作的第一部分。现在我在将 xml 文本设置为 QTextEdit 时遇到了问题。例如,我有一个包含此 xml 文件的 QDomDocument 对象:

<?xml version="1.0" encoding="UTF-8"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.2">
  <office:automatic-styles>
    <style:style style:name="c0" style:family="text">
      <style:text-properties fo:font-family="Sans"/>
    </style:style>
    <style:style style:name="p1" style:family="paragraph">
      <style:paragraph-properties/>
    </style:style>
    <style:style style:name="c10" style:family="text">
      <style:text-properties fo:font-family="Sans" fo:font-size="14pt" style:text-underline-style="none" fo:color="#ff0004"/>
    </style:style>
    <style:style style:name="c8" style:family="text">
      <style:text-properties fo:font-family="Sans" fo:font-size="14pt" style:text-underline-style="solid"/>
    </style:style>
    <style:style style:name="c6" style:family="text">
      <style:text-properties fo:font-style="italic" fo:font-family="Sans" fo:font-size="14pt"/>
    </style:style>
    <style:style style:name="c4" style:family="text">
      <style:text-properties fo:font-weight="bold" fo:font-family="Sans" fo:font-size="14pt"/>
    </style:style>
  </office:automatic-styles>
  <office:body>
    <office:text>
      <text:p text:style-name="p1"><text:span text:style-name="c4">BOLD</text:span></text:p>
      <text:p text:style-name="p1"><text:span text:style-name="c6">ITALIC</text:span></text:p>
      <text:p text:style-name="p1"><text:span text:style-name="c8">UNDERLINED</text:span></text:p>
      <text:p text:style-name="p1"><text:span text:style-name="c10">RED TEXT</text:span></text:p>
    </office:text>
  </office:body>
</office:document-content>

现在我想将此 QDomDocument 文本设置为 QTextEdit。我尝试使用这一行来做到这一点:

editor->setHtml(doc.toString()); // editor is a QTextEdit object and doc is QDomDocument

这是我的问题。在这一行之后,我的编辑器中有一个纯文本(没有任何格式、颜色等)。我该如何解决这个问题?

4

0 回答 0