Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What am I doing wrong in this sequence ?
Forum Update on Monday, May 27th 2025

What am I doing wrong in this sequence ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 217 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    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...

    Screenshot from 2022-08-30 22-27-04.png

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      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 return false.

      So you might try either:

      1. passing the QTextDocument::FindBackward flag to QTextEdit::find() (just to see if that is the issue); or
      2. 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 via QTextEdit::setText() etc) then the internal cursor would likely be considered atEnd() to begin with, and calls to QTextEdit::append() will just keep moving the cursor to the new end each time. Then QTextEdit::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.

      A 1 Reply Last reply
      3
      • Paul ColbyP Paul Colby

        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 return false.

        So you might try either:

        1. passing the QTextDocument::FindBackward flag to QTextEdit::find() (just to see if that is the issue); or
        2. 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 via QTextEdit::setText() etc) then the internal cursor would likely be considered atEnd() to begin with, and calls to QTextEdit::append() will just keep moving the cursor to the new end each time. Then QTextEdit::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.

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved