tags:

views:

157

answers:

2

Qt3.3 used to allow for multiple selections in the QTextEdit widget by calling the setSelection() function and specifying a different selection id (selNum) as the last argument in that function.

In Qt4, to create a selection, I do it by creating a QTextCursor object and call the setPosition() or movePosition() methods. I have no problems being able to create a single selection of text. I am, however, unable to find a way to create multiple selections. The methods in Qt4 do not have an argument which allows you to set a selection id, nor can i find any other function in the QTextCursor or QTextEdit which looks like it might allow me to do so.

Has this feature been completely removed from Qt4? or has is there a new and different way of doing it?

Thanks.

Ronny

A: 

How about creating multiple cursors (QTextCursor), each selection a different portion of the text. Would that work for you?

Eli Bendersky
I tried that, it doesnt give me what i want though. But perhaps im doing it wrong. I tried creating several QTextCursor objects, and each of them is capable of storing their own separate selection information. But when it comes to using the setTextCursor() method for the QTextEdit widget, in order to make them visible, it only displays one selection at a time. As soon as i call it again with a different QTextCursor object as an argument, it erases the old selection and replaces it with the new one. Is there maybe another function similar to setTextCursor() that will do the trick?
Ronny
@Ronny: what are you trying to do - show all the selections to the user? Or copy text from all of them?
Eli Bendersky
I wanted to show the selections visually. And now i realise how easy the answer actually was, and how stupid i was for not thinking of it. All I have to do is change the background colour for those sections of text.
Ronny
@Ronny: yep. I think Qt changed how this works *conceptually* in v4, so now these things have different solutions. Had you wanted to copy all text, you could do it from each QTextCursor in its turn
Eli Bendersky
+1  A: 

The solution, i realise now is actually quite simple.

To graphically visualise all the various selections (separate QTextCursor objects), instead of calling the setTextCursor() method for the QTextEdit widget for each of the selections, i change the background color of each of those sections of text by calling the setCharFormat() method for each of those QTextCursor objects.

Ronny