Results 1 to 5 of 5

Thread: Multiple selection in QTextEdit

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    May 2006
    Location
    Bangalore
    Posts
    23
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple selection in QTextEdit

    For multiple selections, you might have to go with a function.

    In Q3TextEdit, you can find a protected function:
    Qt Code:
    1. void Q3TextEdit::setSelection(int paraFrom, int indexFrom, int paraTo, int indexTo, int selNum)
    To copy to clipboard, switch view to plain text mode 
    As far as I could get it,
    For paraForm you need to give the index of starting Paragraph.
    For paraTo you need to give index of ending Paragraph.

    IndexFrom and IndexTo are actually cursur positions in the respective starting and ending paragraphs.

    Obviously, give a different selNum each time.

    PASTED FROM q3textedit.cpp
    ---------------------------------
    [HTML]/*!
    Sets a selection which starts at position \a indexFrom in
    paragraph \a paraFrom and ends at position \a indexTo in paragraph
    \a paraTo.

    Any existing selections which have a different id (\a selNum) are
    left alone, but if an existing selection has the same id as \a
    selNum it is removed and replaced by this selection.

    Uses the selection settings of selection \a selNum. If \a selNum
    is 0, this is the default selection.

    The cursor is moved to the end of the selection if \a selNum is 0,
    otherwise the cursor position remains unchanged.

    \sa getSelection() selectedText
    */[/HTML]


    Thereafter you can use:
    Qt Code:
    1. void Q3TextEdit::getSelection(int *paraFrom, int *indexFrom, int *paraTo, int *indexTo, int selNum) const
    To copy to clipboard, switch view to plain text mode 

    You might have to dig into some codes in order to get info about QTextDocument, QTextParagraph and QTextCursor.
    Out of these, QTextDocument, and QTextCursor is now documented in Qt4.

    Using all these classes only you can have advanced selection facilities like Column selections (CTRL+ALT+mouse drag like in VC++ and TextPad).

    - Shobhit
    Last edited by bits; 30th June 2006 at 20:25. Reason: remove word "undocumented". Also add about QTextDocuement and QTextCursor being documented in Qt4.
    The Keyboard Is Mightier Than The Sword!

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 07:52
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  3. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23
  4. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  5. Replies: 25
    Last Post: 15th January 2006, 00:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.