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. QTextEdit change font of individual paragrahs before rendering
Qt 6.11 is out! See what's new in the release blog

QTextEdit change font of individual paragrahs before rendering

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.3k 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.
  • T Offline
    T Offline
    TomDuhamel
    wrote on last edited by
    #1

    I'm having a little trouble with this one small thing. I'm a recent player with Qt, but got years of experience with a different framework in C++.

    I'm using a QTextEdit. I need to change the font attributes of a paragraph just before it is rendered. These attributes are unknown when the text is loaded, and the user can decide arbitrarily to give each paragrah a different "style". Bold/Italic/Underlined on individual words must be preserved, but any other shape of text formatting isn't allowed to be included in the block, these needs to be decided by the application.

    Setting charFormat on the block doesn't work, because setting it after text is loaded does nothing. Furthermore, I'd rather not have formating information included in the text.

    As I understand, I need to set some font just before the text layout engine quicks it, but I don't know where it has to be done.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      Hi,

      I don't have much experience with rich text editing in Qt, so I hope I don't mislead you.

      According to the "QTextCursor documentation":http://doc.qt.io/qt-5/qtextcursor.html#setBlockCharFormat setting the character format for an already inserted text block is possible. So it seems that you should navigate to the block in question with QTextCursor and use QTextCursor::setBlockCharFormat() to apply a different QTextCharFormat to that text block.

      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