Delete whole line : QTextEdit



  • This is one way to delete whole line from QTextEdit.

    You have any more?

    me is pointer to qtextedit

     @         me->setFocus();
        int pos;
        QTextCursor tc= me->textCursor();
        pos=tc.columnNumber();
        tc.select(QTextCursor::LineUnderCursor);
        QString str=tc.selectedText();
        tc.removeSelectedText();
    
        tc.movePosition(QTextCursor::NextBlock,QTextCursor::MoveAnchor);
        tc.insertText(str);
        tc.insertBlock();
        tc.movePosition(QTextCursor::PreviousBlock,QTextCursor::MoveAnchor);
        tc.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
        me->setTextCursor(tc);
        return true;
    

    @



  • You can position a cursor at beginning of the line and imitate key press CTRL+K, the docs say this key binding should work and delete rest of line, but it didn't work for me :(



  • Neither for me

    Many shortcut keys are not working as per doc or expectations.

    My solution working nicely. Only in this new version 4.6.3 it stops deleting empty lines.



  • [quote author="Yash" date="1284399692"]
    Many shortcut keys are not working as per doc or expectations.
    Only in this new version 4.6.3 it stops deleting empty lines.[/quote]

    I think you should log a bug for shortcut keys not working in "http://bugreports.qt.nokia.com":http://bugreports.qt.nokia.com

    I'm on 4.7RC and since there is no selection, the empty line is not removed. Probably you should move the cursor to the beginning of the next line before making the selection. The line break will also be included in your selection and then you can remove the whole line ...



  • It was working on 4.6.2 perfectly.

    Yea I'll post bugs. Just want to make sure it just happening with me or others also having same issue.


Log in to reply
 

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