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. QTextCursor changing place with find function in QPlainTextEdit
Qt 6.11 is out! See what's new in the release blog

QTextCursor changing place with find function in QPlainTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.3k Views 2 Watching
  • 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.
  • R Offline
    R Offline
    Rajarshi
    wrote on last edited by
    #1

    bool QPlainTextEdit::find(const QString &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags())
    Finds the next occurrence of the string, exp, using the given options. Returns true if exp was found and changes the cursor to select the match; otherwise returns false.

    In this I have a QTextCursor and I want to change the position of the QtextCursor to the place where the text takes place but in the description I do not see any argument but it says it does return the cursor but my QTextCursor place does not change.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you show how you are using QCursor with find ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rajarshi
        wrote on last edited by
        #3

        I am trying to use QTextCursor as to then highlight the text

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rajarshi
          wrote on last edited by
          #4

          basically I am trying to use QTextCursor to find a text and highlight it yellow

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rajarshi
            wrote on last edited by
            #5

            QString qstr4 = QString::fromStdString(tokens2.at(machine.line2 + 1));
            u = text->find(qstr4, QTextDocument::FindCaseSensitively);
            qDebug() << text->cursor().pos() << endl;
            cursor.mergeCharFormat(format);
            cout << cursor.position() << endl;

            but cout cur.position always gives me -1

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I don't see any check regarding the success of the find.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rajarshi
                wrote on last edited by
                #7

                it does highlight the text gray when it is selected but how can I change it to yellow?

                mrjjM 1 Reply Last reply
                0
                • R Rajarshi

                  it does highlight the text gray when it is selected but how can I change it to yellow?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Rajarshi
                  Hi
                  Look here
                  https://forum.qt.io/topic/89365/trying-to-select-one-line-in-qplaintextedit-using-qtextcursor/5
                  It color it red but you can just change color used.

                  1 Reply Last reply
                  2

                  • Login

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