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

QTextCursor

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 986 Views 1 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.
  • D Offline
    D Offline
    Dmon
    wrote on last edited by
    #1

    How can I write a function that will search through a QTextEdit that contains a .txt file for example and then find all email addresses and phone numbers and change them to bold? I am told that I need to use QTextCursor somehow to do this.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dmon
      wrote on last edited by
      #2

      This is what I have so far:
      @void MakeDisplay::processDoc(){
      QTextDocument doc = text->toPlainText();
      QTextCursor cursor(text->textCursor());
      for (int i=0;i < doc.size();i++)
      {
      cursor.setPosition(i-1,0);
      if (doc[i] = '@')
      {
      cursor.blockFormat()
      }
      }

      }
      @

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dmon
        wrote on last edited by
        #3

        now changed to:

        @void MakeDisplay::processDoc(){
        QString doc = text->toPlainText();
        QTextCursor cursor = text->textCursor();
        QTextCharFormat format;
        format.setFontWeight(75);
        for (int i=0;i < doc.size();i++)
        {
        if (doc[i] == '@')
        {
        cursor.select(QTextCursor::WordUnderCursor);
        cursor.setPosition(i, QTextCursor::MoveAnchor);
        cursor.setPosition(i, QTextCursor::KeepAnchor);
        cursor.mergeCharFormat(format);

            }
        }
        

        }@

        which does not work, but at least compiles with no errors :D

        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