Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    [SOLVED] String selected by mouse in QTextEdit

    General and Desktop
    2
    4
    5007
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      zerg2011 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 == 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]

      1 Reply Last reply Reply Quote 0
      • J
        Jupiter 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

        1 Reply Last reply Reply Quote 0
        • Z
          zerg2011 last edited by

          Jupiter ,
          Yes. It works.

          I've missed that wonderful function.

          Thank you very much.

          1 Reply Last reply Reply Quote 0
          • J
            Jupiter last edited by

            your welcome,
            please mark the thread as solved

            1 Reply Last reply Reply Quote 0
            • First post
              Last post