What am I doing wrong in this sequence ?
-
The task of the attached code is to find text "Controller" in QEditText widget.
I want to change the color of the word "Controller" therefore I need its actual
physical location in the widget.The attached shot shows that a word "Controller" exists in the widget....
However " find" fails to find it.....
Is the sequence incorrect?
Or what else is wrong ?PS I did try another words to make sure I do not have a typo...
-
Hi @AnneRanch, the only thing that comes to mind, is that the cursor might already be at then end, and since
QTextEdit::find()
only searches forward, in that case it will returnfalse
.So you might try either:
- passing the
QTextDocument::FindBackward
flag toQTextEdit::find()
(just to see if that is the issue); or - resetting the cursor before calling
QTextEdit::find()
.
Note, I'm just speculating here (from perusing the Qt code), but if you only ever
QTextEdit::append()
to the control from empty (as opposed to setting new text viaQTextEdit::setText()
etc) then the internal cursor would likely be consideredatEnd()
to begin with, and calls toQTextEdit::append()
will just keep moving the cursor to the new end each time. ThenQTextEdit::find()
will search forward from the end, finding nothing (because there's nothing left, after the end).Anyway, give the above suggestions a go... they'll at least give us more info to go on :)
Cheers.
- passing the
-
Hi @AnneRanch, the only thing that comes to mind, is that the cursor might already be at then end, and since
QTextEdit::find()
only searches forward, in that case it will returnfalse
.So you might try either:
- passing the
QTextDocument::FindBackward
flag toQTextEdit::find()
(just to see if that is the issue); or - resetting the cursor before calling
QTextEdit::find()
.
Note, I'm just speculating here (from perusing the Qt code), but if you only ever
QTextEdit::append()
to the control from empty (as opposed to setting new text viaQTextEdit::setText()
etc) then the internal cursor would likely be consideredatEnd()
to begin with, and calls toQTextEdit::append()
will just keep moving the cursor to the new end each time. ThenQTextEdit::find()
will search forward from the end, finding nothing (because there's nothing left, after the end).Anyway, give the above suggestions a go... they'll at least give us more info to go on :)
Cheers.
@Paul-Colby BINGO! It was the cursor position causing the "problem" . This just proves that one cannot have enough debugging code -if I checked the cursor position AFTER each "append" or reset it....
Thanks very much , appreciate your help,SOLVED
- passing the