Results 1 to 5 of 5

Thread: Multiple selection in QTextEdit

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Multiple selection in QTextEdit

    Hi,

    can we have multiple selection of text in QTextEdit?

    Thanks a lot

  2. #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!

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple selection in QTextEdit

    Quote Originally Posted by bits
    For multiple selections, you might have to go with an undocumented function.
    How come Q3TextEdit::setSelection() is not documented, if you have just pasted its documentation in your previous post? And what's this?

  4. #4
    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

    Quote Originally Posted by jacek
    How come Q3TextEdit::setSelection() is not documented, if you have just pasted its documentation in your previous post? And what's this?
    Ok. I must admit it was a mistake to say that setSelection() and getSelection() are undocumented.
    The Keyboard Is Mightier Than The Sword!

  5. #5
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple selection in QTextEdit

    Hi,

    I have looked into the documentation for sometime now and have not found anything that can solve the problem. First I do not want to use Q3TextEdit but QTextEdit, because I think we can do much more with QTextEdit that Q3TextEdit.

    Ok, now let me explain the whole thing in detail. Let us consider the following text.

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

    In the text above I should be able to select "existing" and "different" (note that they are two words in the same line) programtically. I should also be able to select "existing" and "alone" (two different words in different lines).

    Also, is there a way by which I can disable the user to select any text but using the code I can select multiple text.

    Can someone please help me with this?

    Thanks a lot.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.