Unsolved how do I properly call find from qplaintextedit?
-
Then you should post them.
We don't have crystal balls at hand to guess what issues you have. -
@PythonQTMarlem said in how do I properly call find from qplaintextedit?:
every try i make i get errormessages!
But they're not Qt related, only a python error message due to missing python knowledge...
-
@Christian-Ehrlicher said in how do I properly call find from qplaintextedit?:
@PythonQTMarlem said in how do I properly call find from qplaintextedit?:
every try i make i get errormessages!
But they're not Qt related, only a python error message due to missing python knowledge...
You are right. I start to learn Python in march.
but the reason i post it here ist, that i don't understand the documentation from https://doc.qt.io/qt-5/qplaintextedit.html#find -
@PythonQTMarlem
Hi
But for
self.texteditor.find(suchwert, QTextDocument.FindWholeWords)
did you define suchwert ? -
I'm sorry, you are right I make a mistake.
This Code works:def textsuchenimeditor(): print("Text suchen im Editor") suchwert = self.editsuchen.text() print(self.texteditor.find(suchwert, QTextDocument.FindWholeWords))
But the result is true and not the position of suchwert in qplaintextedit.
i want to mark the found value in qplaintextedit. What do I have to do? -
@PythonQTMarlem Please read documentation: https://doc.qt.io/qt-5/qtextedit.html#find
"Returns true if exp was found and changes the cursor to select the match" -
You're right! Since I can do Delphi, Java and C #, I think Python has to work the same way. But sometimes Python is very different!
This simple code is enough to realize searches and further searches:
```
def textsuchenimeditor():
suchwert = self.editsuchen.text()
sucherfolg = self.texteditor.find(suchwert, QTextDocument.FindCaseSensitively)
if sucherfolg == False:
print("Suchbegriff konnte nicht gefunden werden!")Thank you for your help!
-
If you really want to be pythonic:
if not suchfolg:
-
@SGaist said in how do I properly call find from qplaintextedit?:
if not suchfolg:
okay, i changed it. thank you!
-
@PythonQTMarlem
Get rid ofsuchfolg
/sucherfolg
completely! :) Simply:if not self.texteditor.find(suchwert, QTextDocument.FindCaseSensitively): print("Suchbegriff konnte nicht gefunden werden!")