QTextEdit: how to divide the ordered list into two when deleting the item



  • Hi, I have a class inheriting from QTextEdit and I'm trying to reimplement the QTextEdit's behavior when you delete the item in the middle of ordered list. Example: consider the following list:

    item 1

    item 2

    item 3

    item 4

    subitem 1

    subitem 2

    item 5

    item 6

    Let's say you want to delete the item 3. So you move the cursor there, press backspace a couple of times until "item 3" text is deleted and when you finally press backspace on empty line corresponding to element 3, by default QTextEdit provides the following resulting list:

    item 1

    item 2

    <empty line>

    item 4

    subitem 1

    subitem 2

    item 5

    item 6

    I'd like to get another result, in particular I'd like to get two lists divided by the empty line remaining from the deleted item. Like this:

    item 1

    item 2

    item 4

    subitem 1

    subitem 2

    item 5

    item 6

    I haven't found notices on this problem in the Internet, it looks like most or even all developers working with Qt and creating rich text editors accept the default way of forming the resulting list provided by QTextEdit in this case. That default behaviour can be observed in LibreOffice (not sure it uses QTextEdit but anyway), Calligra Word and other free office suites.

    I tried to move in two directions:

    Reimplement the keyPressedEvent method for my class to catch the backspace pressing while the cursor is inside the list and then process things manually (backup the items below the deleted one, delete them from the list along with the removed item, then insert another list and fill it from backuped data). It even works somehow but I've struggled a lot of issues with content-awareness: it there are multiple subitems in the part of the list below the deleted element, it's very easy to screw it up; if there is a list below the one you are working with, it's indentation and numbers sometimes go off as well.

    I tried to use "insertHtml":http://qt-project.org/doc/qt-4.8/qtextcursor.html#insertHtml method of QTextCursor class to end the list with "</ol>" html but it looks like for some reason this insertion is just not accepted at all, I can't even see it in the html returned by QTextEdit::html().

    I wonder if someone has any experience with this or somehow similar problem and could share it with me. I use Qt version 4.8.3 on Linux x86_64, just in case.



  • I seem to have found the solution and posted it to "github":https://github.com/d1vanov/DivListTextEdit.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.