Results 1 to 6 of 6

Thread: How to convert text to HTML in QTextEdit

  1. #1
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to convert text to HTML in QTextEdit

    I am writing simple chat and I have simple problem. So, if I send message from client to server, this message is viewed as text but it should be viewed as HTML because in this message are HTML tags. Of course I use QTextEdit to box to display all messages. Can somebody show how Can I display text as HTML? Thanks for reply.

  2. #2
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: How to convert text to HTML in QTextEdit

    http://doc.trolltech.com/4.6/qtextedit.html#html-prop

    You can use that to get the text as html
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  3. #3
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to convert text to HTML in QTextEdit

    I have a piece of code, in variable "line" is text with html tags. I don't know how to add line in message box with converted text to html

    Qt Code:
    1. void SimpleChatClient::receiveMessage() {
    2. qint64 bytes = buffer->write(socket->readAll());
    3. buffer->seek(buffer->pos() - bytes);
    4. while (buffer->canReadLine()) {
    5. QString line = buffer->readLine();
    6. chat->append(line.simplified().toUtf8());
    7. QApplication::alert(this);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Roszko; 30th December 2009 at 17:47.

  4. #4
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to convert text to HTML in QTextEdit

    Something like:
    Qt Code:
    1. QTextCursor tc(chat->document());
    2. tc.movePosition(QTextCursor::End);
    3. tc.insertHtml(myHtml);
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to numbat for this useful post:

    Roszko (31st December 2009)

  6. #5
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to convert text to HTML in QTextEdit

    Thank you very well, but I have another problem...
    Is in QTextEdit too much messages the window isn't scrolling
    is there any other method to do this with "append" method ?

  7. #6
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to convert text to HTML in QTextEdit


  8. The following user says thank you to numbat for this useful post:

    Roszko (31st December 2009)

Similar Threads

  1. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  2. Replies: 2
    Last Post: 24th January 2009, 18:30
  3. put html text into a qtextedit
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2008, 19:44
  4. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  5. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.