Results 1 to 4 of 4

Thread: QTextEdit and inserting HTML

  1. #1
    Join Date
    Mar 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextEdit and inserting HTML

    I have a QPlainTextEdit widget that I insert HTML into via moving the cursor along.

    What I have noticed is that if there are things that are in < > tags but are NOT valid html elements, then QPlainTextEdit seems to fail.

    Qt Code:
    1. QString txt = "You have the following commands: <br />read <#/next>, note <title>, remove #, list <from #/last>, marker <#/reset>";
    To copy to clipboard, switch view to plain text mode 

    When do the following
    Qt Code:
    1. ui->txtOutput->moveCursor(QTextCursor::End);
    2. ui->txtOutput->textCursor().insertHtml(txt);
    3. ui->txtOutput->setTextCursor(prevCursor);
    To copy to clipboard, switch view to plain text mode 

    I get the following showing up in the QPlainTextEdit widget


    You have the following commands:
    read , note

    Is is possible to some how.. have QPlainTextEdit ignore non-valid HTML elements? Then again, I'm not 100% sure this is my issue, but it seems iike it so far.

    (on a side note, is there a [pre] for things that are not code?)
    Last edited by OnyxDragun; 28th May 2014 at 00:17.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit and inserting HTML

    You want it to ignore invalid html tags but still respect valid ones? If so then you have to preprocess your text and replace all angle brackets with html entities.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit and inserting HTML

    See http://qt-project.org/doc/qt-4.8/qt.html#escape for a helper function that escapes HTML entities

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    OnyxDragun (28th May 2014)

  5. #4
    Join Date
    Mar 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit and inserting HTML

    Quote Originally Posted by anda_skoa View Post
    See http://qt-project.org/doc/qt-4.8/qt.html#escape for a helper function that escapes HTML entities
    That was the key! Thanks! Now my MUD client supports ansi colours properly as it converts them to html for the QPlainTextEdit.

Similar Threads

  1. QTextEdit insert html
    By abrahametalero in forum Newbie
    Replies: 4
    Last Post: 12th February 2011, 18:58
  2. Inserting html and plain text in QTextEdit
    By alexandernst in forum Newbie
    Replies: 8
    Last Post: 13th April 2010, 19:53
  3. QTextEdit and Html
    By giusepped in forum Qt Programming
    Replies: 1
    Last Post: 28th October 2008, 17:20
  4. Problem with inserting text into QTextEdit
    By xorrr in forum Qt Programming
    Replies: 0
    Last Post: 6th February 2006, 11:45
  5. [Qt 4.1]using html in QTextEdit from designer
    By patcito in forum Qt Programming
    Replies: 5
    Last Post: 16th January 2006, 22:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.