Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] String selected by mouse in QTextEdit
QtWS25 Last Chance

[SOLVED] String selected by mouse in QTextEdit

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 5.3k Views
  • 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 Offline
    Z Offline
    zerg2011
    wrote on last edited by
    #1

    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
    0
    • J Offline
      J Offline
      Jupiter
      wrote on last edited by
      #2

      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
      0
      • Z Offline
        Z Offline
        zerg2011
        wrote on last edited by
        #3

        Jupiter ,
        Yes. It works.

        I've missed that wonderful function.

        Thank you very much.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jupiter
          wrote on last edited by
          #4

          your welcome,
          please mark the thread as solved

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved