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. Problems with textfinder example

Problems with textfinder example

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 332 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
    AndrzejB
    wrote on last edited by
    #1

    First is when I change QTextDocument::FindWholeWords to QTextDocument::FindFlag(0).
    It highlight from found substring to end of word.
    I know it is because

    highlightCursor.movePosition(QTextCursor::WordRight,
                                                 QTextCursor::KeepAnchor);
    

    I must move right of substring len; is any better way than N call following?

    highlightCursor.movePosition(QTextCursor::Right,
                                                 QTextCursor::KeepAnchor);
    

    Second problem is worse: while in exmaple

    colorFormat.setForeground(Qt::red);
    

    works fine, in my editor this not works, only works

    colorFormat.setBackground(Qt::yellow);
    

    maybe because I have highlighter?

    Third problem: after highlighting found substring, text has flag isModified.
    in example at start is

    // undo previous change (if any)
        document->undo();`
    

    How correctly handle it? Document can have real change or not.

    jsulmJ 1 Reply Last reply
    0
    • A AndrzejB

      First is when I change QTextDocument::FindWholeWords to QTextDocument::FindFlag(0).
      It highlight from found substring to end of word.
      I know it is because

      highlightCursor.movePosition(QTextCursor::WordRight,
                                                   QTextCursor::KeepAnchor);
      

      I must move right of substring len; is any better way than N call following?

      highlightCursor.movePosition(QTextCursor::Right,
                                                   QTextCursor::KeepAnchor);
      

      Second problem is worse: while in exmaple

      colorFormat.setForeground(Qt::red);
      

      works fine, in my editor this not works, only works

      colorFormat.setBackground(Qt::yellow);
      

      maybe because I have highlighter?

      Third problem: after highlighting found substring, text has flag isModified.
      in example at start is

      // undo previous change (if any)
          document->undo();`
      

      How correctly handle it? Document can have real change or not.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @AndrzejB said in Problems with textfinder example:

      movePosition

      it has a third parameter...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AndrzejB
        wrote on last edited by AndrzejB
        #3

        Best result are without highlightCursor.movePosition because highlightCursor = plainEdit->document()->find() is enough.
        I don't know why colorFormat.setForeground(Qt::red) doesn't work while colorFormat.setBackground(Qt::yellow) works

        Partial solution: If I removed highlighter, my foreground color changed to red
        But how to use highlighter and themes (I am using themes from KF5SyntaxHighlighting) to change it?

        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