multiple cursor selection
Hello. How can I achieve multiple cursor selection, like here :
http://i.imgur.com/PF6sX2v.png
so I can rewrite everything that is found.
So far I got this:
http://i.imgur.com/wY66D5l.png ( can only rewrite last word )
I'm using plainTextEdit widget.
Re: multiple cursor selection
Re: multiple cursor selection
Here is code I use:
Code:
word = self.lineEdit.text()
extraSelections = []
while(self.
plainTextEdit.
find(word,QtGui.
QTextDocument.
FindWholeWords)): '''
selection = QtWidgets.QTextEdit.ExtraSelection()
selection.format.setProperty(QtGui.QTextFormat.FullWidthSelection, True)
selection.cursor = self.plainTextEdit.textCursor()
selection.cursor.clearSelection()
extraSelections.append(selection)
'''
cursor = self.plainTextEdit.textCursor()
currentWord
= QtWidgets.
QTextEdit.
ExtraSelection() Color
= QtGui.
QColor(191,
191,
191,
189) currentWord.format.setBackground(Color)
currentWord.cursor = cursor
extraSelections.append(currentWord)
self.plainTextEdit.setExtraSelections(extraSelections)
self.plainTextEdit.setFocus()
What am I doing wrong?
Re: multiple cursor selection
What is the effect you are getting? How many items does extraSelections have before line #22? Is the cursor for each of the selections set properly?
Re: multiple cursor selection
You can see on second picture what effect I'm getting, if I'm reading this right for(test example) I have
[<PyQt5.QtWidgets.ExtraSelection object at 0x7f25924b1dd8>, <PyQt5.QtWidgets.ExtraSelection object at 0x7f25924b1c88>, <PyQt5.QtWidgets.ExtraSelection object at 0x7f25924b1eb8>]
3 items in extraSelections
Re: multiple cursor selection
That would probably mean your find() call is incorrect. Maybe you should use QTextDocument::find() instead?
Re: multiple cursor selection
No matter what I try every word is painted correctly, but only last word found is selected.
Re: multiple cursor selection
That's because "extra selections" are not real selections. The logic of your program should update all cursors at the same time while you are performing the edit.
Re: multiple cursor selection
Since english is not my native language, maybe I didn't explain it right, but if you look at these two videos:
this is what I want:
https://www.youtube.com/watch?v=Ux3_...ature=youtu.be
and this is what I have at this moment:
https://www.youtube.com/watch?v=NouO...ature=youtu.be
Quote:
the logic of your program should update all cursors at the same time while you are performing the edit.
that's what I wish to achieve, but I don't know how.
Re: multiple cursor selection
QTextCursor API can be used to edit the document. So if you want to enter "foo" in 10 places, you need to have cursors set to each of the place and use its API to insert "foo" through each cursor.