[SOLVED] String selected by mouse in QTextEdit
-
wrote on 17 Nov 2011, 11:55 last edited by
Hi
I need to know which text is selected in QTextEdit by user.
I mean the text selected by mouse . I.e. the text that can be copied into the clipboard.I would to have the selected string , its length and position in text.
I'm using the foolowing code :
@
QTextEdit textViewer_ ;
QTextDocument *doc = textViewer_ . document() ;
QTextCursor crs( doc ) ;//textViewer_ . cursorRect () ; int beginPos = crs . selectionStart() ; int endPos = crs . selectionEnd() ; int pos = crs . position() ;
@
The result of this code :
beginPos == 0
endPos == 0
pos == 0How I use it :
I select the chunk of text in the QTextEdit widget
then press the button which execute specified code.Could you please advise the proper way this task solving ?
Thanks.
[edit: please use @ code tags , thanks, Eddy]
-
wrote on 17 Nov 2011, 12:22 last edited by
hav you tried @textViewer_.textCursor()@ to get the cursor?
you simply create a new one, so it just a logical behavior that its position is 0
-
wrote on 17 Nov 2011, 12:34 last edited by
Jupiter ,
Yes. It works.I've missed that wonderful function.
Thank you very much.
-
wrote on 17 Nov 2011, 12:42 last edited by
your welcome,
please mark the thread as solved
4/4