Proper selection from QPlainTextEdit
-
Hi everyone.
Let's see on the next example of QPlaintTextEdit containing
@
text_text
text_text place_1/place_2/place_3 text_text
text
@I need to get string "place_1/place_2/place_3" and set it to some QString variable by placing cursor on this very string (by clicking on this part of text or by changing cursor position by arrows). A tried several ways to do it but they didn't help. I can use TextCursor::WordUnderCursor selection but symbol '/' is a split symbol what means I can't select this entire string with this option. Another option is to get an entire line from text browser and somehow determine position of considering part in this somehow. The other option is to use QTextBlockFormat but I can't understand what is a block of text by default (lines, some number of chars, etc) and how I can change the policy of splitting text on blocks.
I think this problem is quite common and there should be an easy way to solve it. Can anyone help?
-
Why not store all the text into a QString then apply QRegExp into it to get the specific string that you needed? Do you actually need to select it by cursor?
-
[quote author="Code_ReaQtor" date="1364997077"]Why not store all the text into a QString then apply QRegExp into it to get the specific string that you needed? Do you actually need to select it by cursor?[/quote]
Yes, I really need to select it by cursor because my task is to make some kind of completer and I have to be sure what part of the text I'm working with. If the text in QPlainTextEdit is split onto blocks by new_lines ('\n') then I can take all the line (because it is a block) and then fetch considering part of the line by using positionInBlock().