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. Wrong QTextCharFormat got from a given position by contentsChange signal of a QTextDocument
QtWS25 Last Chance

Wrong QTextCharFormat got from a given position by contentsChange signal of a QTextDocument

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

    Hello,
    let's say I have a QTextDocument with 5 characters, I manually select the character at position 3 using a QTextEdit and I apply a fontWeight invoking setFontWeight. Inside a slot connected to the contentsChange signal of the document I create a QTextCursor initializing it with textCursor() and I fetch the QTextCharFormat at the position above (3), it does not contain the applied font weight.

    jsulmJ 1 Reply Last reply
    0
    • A anphetamina

      Hello,
      let's say I have a QTextDocument with 5 characters, I manually select the character at position 3 using a QTextEdit and I apply a fontWeight invoking setFontWeight. Inside a slot connected to the contentsChange signal of the document I create a QTextCursor initializing it with textCursor() and I fetch the QTextCharFormat at the position above (3), it does not contain the applied font weight.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @anphetamina In https://doc.qt.io/qt-5/qtextdocument.html#contentsChange
      there is "The signal is emitted before the document's layout manager is notified about the change. This hook allows you to implement syntax highlighting for the document.". So, maybe the change is not yet applied when the signal is emitted? Did you check where the cursor actually is (is it at correct position?)?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        anphetamina
        wrote on last edited by anphetamina
        #3

        I place the cursor at the position emitted by the signal contentsChange

        "maybe the change is not yet applied when the signal is emitted? "

        No, because I'm able to fetch the correct format using currentCharFormat(), but it works only when the textCursor() position is right after the position in which the character has been placed. Let's say I made the selection from right to the left, currentCharFormat() picks the format of the previous character.

        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