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. QTextDocument: get formated text
Forum Updated to NodeBB v4.3 + New Features

QTextDocument: get formated text

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 178 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.
  • K Offline
    K Offline
    Kapitan Papiroveho Lodstva
    wrote on last edited by
    #1

    Hi guys,
    I need to get formated words (misspeling underlined) from QTextDocument.
    How do I get words with specific format and their position in document?

    I had something like...

    for( auto textBlock = document()->begin(); textBlock != document()->end(); textBlock = textBlock.next() )
            {
                qDebug() << "textBlock::text: " << textBlock.text();
                auto formats = textBlock.textFormats();
    
                for (auto t = textBlock.begin(); t != textBlock.end(); ++t)
                {
                    qDebug() << "";
                    auto fragment = t.fragment();
                    qDebug() << fragment.text();
                    auto format = fragment.charFormat();
                    qDebug() << format.fontUnderline();
                    qDebug() << format.underlineStyle();
                    qDebug() << format.underlineColor();
                    qDebug() << "";
                }
            }
    

    But that returned the entire text in document as only element and without any formating.

    How else to get it? Or how to get to individual elements?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kapitan Papiroveho Lodstva
      wrote on last edited by
      #2

      QTextEdit::document()->textCursor().block().layout()->formats();

      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