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. Insert html in new line after pressing return/enter in QTextEdit -PySide6
Forum Updated to NodeBB v4.3 + New Features

Insert html in new line after pressing return/enter in QTextEdit -PySide6

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 300 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
    tIk90wT
    wrote on last edited by tIk90wT
    #1

    I'm trying to insert special characters at beginning of new lines in QTextEdit when I press enter/return, like how QTextList have decorations. But the following code inserts the html on the same line before moving to the next line.

    class ed(QTextEdit):
        def __init__(self):
            super(ed, self).__init__()
            self.installEventFilter(self)
    
        def insertLine(self):
            cur = self.textCursor()
            cur.insertHtml("<span>&#10023;</span><span>&nbsp;</span>")
            self.setCursor(cur)
    
        def eventFilter(self, o, e):
            if e.type() == QEvent.KeyPress:
                if e.key() == Qt.Key_Return:
                    self.insertLine()
    

    I tried

    KeyRelease
    

    and it kind of works. But it starts inserting typed letters if i type fast while moving to next line.

    I tried to make use of QTextListFormat but it doesn't support custom decorations.

    Can I make use of QTextList to achieve what I'm trying to do?
    How to insert the html after the cursor moves to next line, not before?

    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