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. I need a function to add some HTML attribute to a QTextObject?

I need a function to add some HTML attribute to a QTextObject?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 253 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.
  • J Offline
    J Offline
    JackMyson
    wrote on last edited by
    #1

    Are there any function act like this in Qt version 6.4.1:

    // a QTextObject inherited class
    QTextCursor cursor = textCursor();
    QtextBlock* blk = cursor.block();
    QTextBlockFormat fmt = blk->format();
    // method I wonder
    fmt.setHtmlAttribute(QTextBlockFormat::HtmlAttr::Style, 
        "font-weight: 700");
    qDebug() << toHtml();
    

    Will output

    ...
    <p style="font-weight: 700">current block</p>
    ...
    

    Without modifying the HTML through setHtml(...) or setFontWeight(int) .

    Is there any way to do that in Qt 6? Thanks!

    JonBJ 1 Reply Last reply
    0
    • J JackMyson

      Are there any function act like this in Qt version 6.4.1:

      // a QTextObject inherited class
      QTextCursor cursor = textCursor();
      QtextBlock* blk = cursor.block();
      QTextBlockFormat fmt = blk->format();
      // method I wonder
      fmt.setHtmlAttribute(QTextBlockFormat::HtmlAttr::Style, 
          "font-weight: 700");
      qDebug() << toHtml();
      

      Will output

      ...
      <p style="font-weight: 700">current block</p>
      ...
      

      Without modifying the HTML through setHtml(...) or setFontWeight(int) .

      Is there any way to do that in Qt 6? Thanks!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @JackMyson
      Qt's rich text handling does not accept arbitrary HTML, only a subset. So I don't think it caters for you just inserting some HTML attribute. I would expect to accomplish your request via setHtml(...) or setFontWeight(int)?

      1 Reply Last reply
      1

      • Login

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