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: adding normal text after html
QtWS25 Last Chance

QTextEdit: adding normal text after html

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 630 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.
  • E Offline
    E Offline
    enne9
    wrote on last edited by
    #1

    Hi,
    if I put a span in QTextEdit using

    cursor.insertHtml("<span style='background-color:" + color + ";display:block'>&nbsp;</span>");
    

    and then I try to write after it interactively (NOT using code, as cursor.insertText()), new spans are added instead of inserting the actual content I enter using the keyboard.

    How can I handle this? Is there a function to restore the normal text after putting the HTML?
    Thanks in advance

    E 1 Reply Last reply
    0
    • E enne9

      Hi,
      if I put a span in QTextEdit using

      cursor.insertHtml("<span style='background-color:" + color + ";display:block'>&nbsp;</span>");
      

      and then I try to write after it interactively (NOT using code, as cursor.insertText()), new spans are added instead of inserting the actual content I enter using the keyboard.

      How can I handle this? Is there a function to restore the normal text after putting the HTML?
      Thanks in advance

      E Offline
      E Offline
      enne9
      wrote on last edited by
      #2

      @enne9 Can someone please help me?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Please show some patience and allow at least 24 hours before bumping your own thread. This forum is run by volunteers that may not live in the same time zone as you.

        Il any case, please provide a minimal compilable example that allows to reproduce your use case.

        You should also add which version of Qt you are using and on what platform.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • E Offline
          E Offline
          enne9
          wrote on last edited by
          #4

          Qt version 5.14.1 on Linux platform.

          About the example, it is nothing specific, it can be reproduced by using a common QTextEdit and adding the line of code I've written before. Then run the application and type whatever character (from the keyboard) right after the HTML character introduced before.

          Let me know if there is something I didn't explain well.
          Thanks

          JonBJ 1 Reply Last reply
          0
          • E enne9

            Qt version 5.14.1 on Linux platform.

            About the example, it is nothing specific, it can be reproduced by using a common QTextEdit and adding the line of code I've written before. Then run the application and type whatever character (from the keyboard) right after the HTML character introduced before.

            Let me know if there is something I didn't explain well.
            Thanks

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

            @enne9
            You do not explain what it is you see, or how you say the HTML ends up which you should show us, after you enter some characters. I don't know what "new spans are added instead of inserting the actual content I enter using the keyboard" means.

            If I try your code (Linux Qt 5.12.2), with color being red, what I see is: a red background on one space, with the cursor immediately to the right of that space. When I type characters they appear, but with the red background. Doubtless because it does not know whether your cursor "position" is after the &nbsp; but still before the </span> versus whether it is after the </span> .

            If I append a <br /> to your HTML, "...>&nbsp;</span><br \>", the cursor starts at the line below and characters now typed do not have the red background.

            You may have to explain exactly what happens to you and what you want/expect.

            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