Results 1 to 3 of 3

Thread: Displaying a formatted text

  1. #1
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Displaying a formatted text

    I need to display a formatted text. The text is a plain text with custom markups. I need to parse the tags and display the formatted text in a window. The text will be read-only. I need to process tags like these:

    - new line (not a new paragraph, just a new line within a paragraph)
    - new paragraph (with and without paragraph indent)
    - indented text
    - coloring, italic, bold
    - simple tables (bullets, "text bullets", that means, the "bullet" is a "heading" which can differ from bullet to bullet while keeping the corresponding texts equally indented). No decorations in the tables, just keep "columns".
    - fixed pitch font
    - detect a clicked URL, pass URL to the default web browser.

    and similar simple formatting tags. The tags can be nested like this:

    :color red.some red text :italic.also in italics:end of italic. continuing red text.:end of color.

    I have checked the related classes in Qt and I got lost immediately. Where should I begin? What should I read or see? What widget should I select for the text window? I have QPlainTextEdit as a placeholder right now. I can display the raw text nicely but this is not what I want.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Displaying a formatted text

    Translate this text to standard HTML and display them with QTextEdit in read only mode.

  3. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Displaying a formatted text

    This is one of the less nice solutions If I understand well, the QTextEdit accepts the <body> .. </body> HTML text with sufficient set of tags. Nevertheless, the original text is not HTML so that I need to translate. Okay, but I cannot append the text element by element because the intermediate text is not valid in general (missing end tags because they weren't reached so far). I need an auxiliary QString where I translate the text and then I need to display the QString as a whole. A single error in the original text can cause losing the whole output. Correct?

    I would appreciate some kind of "rich text edit", perhaps, something derived from QTextEdit or QPlainTextEdit with formatting member functions. But this means understanding the bags or QTextManyThings objects.

Similar Threads

  1. Drawing Rich Formatted Text with QPainter
    By millsks in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2009, 19:59
  2. Displaying all characters in text edit
    By chadkeck in forum Qt Programming
    Replies: 1
    Last Post: 17th September 2008, 01:48
  3. formatted text in QTreeWidgetItem
    By swiety in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2007, 16:26
  4. displaying text
    By me_here_me in forum Qt Programming
    Replies: 2
    Last Post: 14th September 2007, 10:48
  5. Displaying Text Quickly
    By taylor34 in forum Qt Programming
    Replies: 6
    Last Post: 2nd March 2006, 14:09

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.