Results 1 to 2 of 2

Thread: highlight in QTextEdit

  1. #1
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    1

    Default highlight in QTextEdit

    Hello,

    I am not using QSyntaxHighlight because I don't know how to use it and my Highlighter works very well but it is the problem it is too slow , I am trying to highlight my own programming language.

    The question is how to get only the part of the String that will be rendered to the user, that will help me a lot because the program only needs to get tokens and replaces a part of the string, my string is too long because I need to encode each token with a long string that QRegExp in QString relace could ignore to find the other tokens without interfering.

    I think QTextEdit uses it internally because when the user scroll down the text it will need to know a starting line and end line to be drawn maybe in it's paint event or something, in that widget, because the text could be greater than the QTextEdit area and the scroll position can change, I am using QT Creator in ubuntu.

    Thank you

    Regards.
    Last edited by ubuntudevelop78; 26th November 2009 at 23:51.

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

    Default Re: highlight in QTextEdit

    It will be easier to do it using QPlainTextEdit. You can use QPlainTextEdit::firstVisibleBlock() to get the first block. As for the last block it is probably easiest to compute it knowing the height of the viewport and font metrics of the font used in the document. Anyway, if you are highlighting your text by introducing html tags into the text of the document, I suggest you don't do that. It's much better and easier to do it using QSyntaxHighlighter.
    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. The following user says thank you to wysota for this useful post:

    ubuntudevelop78 (27th November 2009)

Similar Threads

  1. Vertical centering of a QTextEdit
    By miwarre in forum Newbie
    Replies: 4
    Last Post: 5th October 2015, 05:01
  2. QTextEdit Performance handling large paragraphs
    By netuno in forum Qt Programming
    Replies: 14
    Last Post: 1st September 2010, 22:58
  3. Drawing on QTextEdit
    By jgrauman in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2009, 09:40
  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.