Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QTextDocument::setHtml() changes font when setting toHtml() output
Forum Updated to NodeBB v4.3 + New Features

[Solved] QTextDocument::setHtml() changes font when setting toHtml() output

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    theoriginalgri
    wrote on 14 Oct 2011, 15:19 last edited by
    #1

    I have some HTML from a QML TextArea (part of qt-components) using Richttext formatting.

    On my c++ side, I have some code which creates a QTextDocument and calls setHtml() with that text. When calling toHtml() immediately on the same document, the output has different font settings than the input

    Code:
    @
    QTextDocument document;
    document.setHtml(d->inputText);

    qDebug() << d->inputText;
    qDebug() << "------------";
    qDebug() << document.toHtml();
    

    @

    Output (as image since Qt devnet cleans out html even in code tags):
    !http://dl.dropbox.com/u/4691970/qtextdocument.png!

    As you can see, the default font changed from "Nokia Pure Text" to "Sans Serif" and it created a new span :(

    I also tried QTextDocument::setDefaultFont() with Nokia Pure Text before and after the setHtml() call, but it does not change anything. How do I prevent QTextDocument from changing the font?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      theoriginalgri
      wrote on 15 Oct 2011, 11:37 last edited by
      #2

      Ok, solved it ...

      It seems like you have to set the default font for QTextEdit because it won't read it from HTML. Don't know why it didn't work for me yesterday. The span creation can't be prevented.

      1 Reply Last reply
      0

      1/2

      14 Oct 2011, 15:19

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved