PDA

View Full Version : Multiple selection in QTextEdit



munna
30th June 2006, 14:57
Hi,

can we have multiple selection of text in QTextEdit?

Thanks a lot

bits
30th June 2006, 20:54
For multiple selections, you might have to go with a function.

In Q3TextEdit, you can find a protected function:

void Q3TextEdit::setSelection(int paraFrom, int indexFrom, int paraTo, int indexTo, int selNum)
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
---------------------------------

/*!
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
*/


Thereafter you can use:

void Q3TextEdit::getSelection(int *paraFrom, int *indexFrom, int *paraTo, int *indexTo, int selNum) const


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

jacek
30th June 2006, 21:11
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 (http://doc.trolltech.com/4.1/q3textedit.html#getSelection)?

bits
30th June 2006, 21:20
How come Q3TextEdit::setSelection() is not documented, if you have just pasted its documentation in your previous post? And what's this (http://doc.trolltech.com/4.1/q3textedit.html#getSelection)?
Ok. I must admit it was a mistake to say that setSelection() and getSelection() are undocumented.

munna
1st July 2006, 08:58
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.