Results 1 to 6 of 6

Thread: Help text color in TextEdit

  1. #1
    Join Date
    Sep 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Help text color in TextEdit

    Hi,
    I want to make error message in TextEdit has red color, so I do like this:
    QString tag1 = "<font color = 'red'>";
    tag1.append(error);
    tag1.append("</font>");
    read_textEdit->append(tag1);
    but when I select that error message in TextEdit, all other message come up in TextEdit after it will become red. If I don't select it, all other message come up in TextEdit will become black color as default. So how can I fix it? I want only the error message has red color only. I try to do like this but it didn't fix the problem of other message become red also if I highlight the error message in TextEdit.

    QString tag1 = "<font color = 'red'>";
    tag1.append(error);
    tag1.append("</font><font color = 'black'></font>");
    read_textEdit->append(tag1);

  2. #2
    Join Date
    Sep 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help text color in TextEdit

    Can anyone help me on this problem?

  3. #3
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help text color in TextEdit

    I also have same problem.
    Last edited by vql; 21st March 2008 at 17:00.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help text color in TextEdit

    Qt docs say:
    Note: The new paragraph appended will have the same character format and block format as the current paragraph, determined by the position of the cursor.
    Try the QTextDocument API:
    Qt Code:
    1. QTextCursor cur( _ui.textEdit->document() );
    2. cur.movePosition( QTextCursor::End, QTextCursor::MoveAnchor );
    3. cur.insertBlock( QTextBlockFormat() );
    4. cur.insertText( message );
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Help text color in TextEdit

    use this function:

    Qt Code:
    1. void WriteLog(QString s, QColor c)
    2. {
    3. if(s.isEmpty())
    4. return;
    5.  
    6. QTextStream theStream(s,IO_ReadOnly);
    7. QString sColor = "<font color="+c.name()+">";
    8. while ( !theStream.atEnd() )
    9. read_textEdit->append(QTime::currentTime().toString() + " " + sColor+theStream.readLine());
    10. //edLog->setParagraphBackgroundColor(edLog->paragraphs()-1,c);
    11. QFile file( "[LOG FILE NAME].log" ); // Write the text to a file
    12. if ( file.open( IO_WriteOnly ) )
    13. {
    14. QTextStream stream( &file );
    15. for(int i=0;i<m_log->paragraphs();i++)
    16. stream << read_textEdit->text(i) << "\r\n";
    17. }
    18. file.close();
    19. }
    To copy to clipboard, switch view to plain text mode 
    this function write the string s to the read_textEdit member and a log file(you do not need to use this "file code" if you do not want log file)
    each time you want to write to a log file or to the read_textEdit member call this function with any color you want

  6. #6
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help text color in TextEdit

    Quote Originally Posted by vql View Post
    I also have same problem.

    QTextEdit not parse HTML <font tag> !

    to understand QTextEdit html tag load this
    http://www.qt-apps.org/content/show....?content=59493
    or export html from
    http://www.qt-apps.org/content/show....?content=67552


    Qt Code:
    1. <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px;
    2. margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;">
    3. <span style=" font-weight:600; color:#ff0000;"> error on red and bold</span>
    4. </p>
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 26th March 2008 at 12:43. Reason: wrapped too long line

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  4. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  5. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02

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.