[SOLVED] String selected by mouse in QTextEdit



  • 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 == 0

    How 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]



  • 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



  • Jupiter ,
    Yes. It works.

    I've missed that wonderful function.

    Thank you very much.



  • your welcome,
    please mark the thread as solved


Log in to reply
 

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