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. Stop QTextCursor from resetting undo stack
QtWS25 Last Chance

Stop QTextCursor from resetting undo stack

Scheduled Pinned Locked Moved Solved General and Desktop
qplaintexteditqtextcursorundo stack
1 Posts 1 Posters 445 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.
  • D Offline
    D Offline
    dhamith93
    wrote on last edited by dhamith93
    #1

    I have a function that check previous line and insert text to the QPlainTextEdit QTextCursor. Problem with my function is it resets the undo stack of the QPlainTextEdit. Is there a way to add my changes to the undo stack instead of resetting it?

    This is how I'm currently doing it:

        QTextBlock textBlock = ui->noteText->textCursor().block();
        QString prevLine = textBlock.previous().text();
    
        if (checkListItem(prevLine)) {
            if (textBlock.text().length() == 0) {
                int spaceCount = getSpaceCount(prevLine);
                QString newLine = QString("").leftJustified(spaceCount, ' ');
    
                if (checkUnorderedListItem(prevLine)) {
                    newLine += "* ";
                } else {
                    newLine += getNextNumber(prevLine) + ". ";
                }
    
                ui->noteText->textCursor().insertText(newLine);
            }
        }
    

    EDIT:

    Because of how my function works, if the previous line checks true and current line is empty when undoing it inserts new text again into the current line.

    I had to create an event filter and override ControlModifier + 'Z' event to make it work.

    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