Results 1 to 3 of 3

Thread: How to set text and font in qTextEdit?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to set text and font in qTextEdit?

    Look at QTextCursor and QTextCharFormat classes.
    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.


  2. The following user says thank you to wysota for this useful post:

    JuKu (28th September 2009)

  3. #2
    Join Date
    Sep 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: How to set text and font in qTextEdit?

    Thank you! The Qt documentation is very good, but there is lots of it. Your keywords pointed me to the right direction.

    To save other noobies an hour or two, here is where the keys were found:
    All Overviews and HOWTOs in general and especially, Supported HTML Subset. I hadn't realized the qTextEdit used HTML inside!

    Here is some example code:
    Qt Code:
    1. ui->TextEdit->setText("1234567890<br>1234567890<br>line3");
    2. QTextCursor cursor(ui->TextEdit->document());
    3. cursor.setPosition(15, QTextCursor::MoveAnchor); // Go to 4th character of second line; the <br> counts as one character.
    4. cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 3); // select three charaters
    5. QString s=cursor.selectedText();
    6. cursor.insertHtml("<FONT color=green style=\"BACKGROUND-COLOR: yellow\">"+s+"</FONT>"); // make them ugly
    To copy to clipboard, switch view to plain text mode 
    The more familiar I get with Qt, the more I like it.

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

    Hossein (24th October 2015)

Similar Threads

  1. Replies: 12
    Last Post: 30th May 2009, 14:29
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. Replies: 2
    Last Post: 24th January 2009, 18:30
  4. QTextEdit and font family
    By giusepped in forum Qt Programming
    Replies: 6
    Last Post: 4th June 2008, 10:17
  5. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03

Tags for this Thread

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.