Recognizing URL while typing
-
Hi, ALL,
Have following issue.Most editors I know can do following:
When I type www.google.com and press "Space Bar> the editor will successfully recognize that text as URL and correctly render it as such.
If I do copy and paste the text that contains such a text, again, the editor will successfully recognize it and render it as such.However, it looks like this is not the case with QTextEdit control.
With this control it looks like I should enter <a href=....... /a> it order for the text to be rendered as URL.
Keep in mind - I am not talking here about click processing - strict rendering.
Is there any styles, or maybe signal I shuold catch in order to render URL properly inside QTextEdit?
And I am not interested in QBrowserEdit. From my google search it looks like this control is for read-only text, which is NOT the case.
Thank you.
-
Can you offer more details about what you want to achieve and about your project? also about Qt version and Os? Do you try to do your own web browser?
-
you would most likely need to scan the current input on every keypress, do pattern matching against what was typed, and identify the patterns that look like URLs. I personally dislike URL identification when I'm typing something in a document or editor. Id rather manually mark it as such afterwards. Very annoying when I type @ and it automatically tries to turn it into a mailto: URL.
-
Hi,
@arsinte_andrei said in Recognizing URL while typing:Can you offer more details about what you want to achieve and about your project? also about Qt version and Os? Do you try to do your own web browser?
Just look at my OP.
I didn't have to write the whole HTML, and the link is rendered as it should.
Or try to do it yourself - when you start replying, try to type "www.google.com" and see how that text will be changed.
Don't click on the link - just see how it will be rendered (blue text).My Qt version is 5.7.1 on Gentoo Linux.
No, not web browser. I specifically said "QTextEdit", right?
Thank you.
-
If you just want it to be blue you can use a QSyntaxHighlighter - also take a look at the example
-
I'm basically looking for something like this
-
I'm not aware that there is a out-of-the-box solution for Qt for this - you have to do it on your own but the QSyntaxHighlighter example is a good starting point.