I'm trying to search for the position of a string in a Qscintilla window.
Here's a piece of (runnable) mock code:
import sys
from PyQt4 import QtGui, Qsci
app = QtGui.QApplication(sys.argv)
window = Qsci.QsciScintilla()
window.show()
# Search in target for string
text = "Hello world"
window.setText(text)
messenger = window.SendScintilla
messenger(window.SCI_SETTARGETSTART, 0)
messenger(window.SCI_SETTARGETEND, len(text))
pos = messenger(window.SCI_SEARCHINTARGET, len(text), "world")
print(pos);
app.exec_()
It searches for the string "world"
in a text editor window currently holding the string "Hello world"
. However the search returns -1
(failed to find string), when the string clearly exists in the text editor window.
What might the problem be?
See http://www.scintilla.org/ScintillaDoc.html#SCI_SEARCHINTARGET: The length
parameter is the length of the text you're searching for, not of the text you're searching in.
This will get you what you want:
pos = messenger(window.SCI_SEARCHINTARGET, len("world"), "world")