Dynamically Syntax Highlighter



  • Hello :) I want to ask again for yours help :)
    In my project to university, I'm creating somthink like editor to webmasters who will support few language like php or javascript, and I have little question about QSytnaxHighlighter :)
    In example of this beautiful is use only static highlight, so if user will enter some data from keyboard, this data will be don't higlight. So I think that somethink like that will be good solution

    @connect(editor,SIGNAL(textChanged ()),this,SLOT(rehighlight ()));@

    but this will take much more memory than I except... so i wanna know, is a another way to do that?



  • The highlighting as in the example (Qt Sources/examples/richtext/syntaxhighlighter) is dynamic. As soon as the user enters text, the highlighting is adapted. Also, there is no connect() necessary if you set up the highlighter with the text document.

    The "Syntax Highlighter Example"http://doc.qt.nokia.com/stable/richtext-syntaxhighlighter.html has some more explanations.



  • Oh, I'm sorry, I must miss that in this Example, but I have another question. Can be QSyntaxHighlighter used with QPlainTextEdit ? If anwser is yes, How can to do this? Because QPlainTextEdit is a Widget and only constructors are:
    @QSyntaxHighlighter(QObject *parent);
    QSyntaxHighlighter(QTextDocument *parent);
    QSyntaxHighlighter(QTextEdit *parent); @



  • You should used the second one, with editor->document() as a parent.



  • yey, it's work's :) thanks, I'm very greatful for yours help :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.