qplaintextedit

Qt Clear Undo History in a QTextEdit/QPlainTextEdit?

喜你入骨 提交于 2019-12-05 17:20:55
I have a QPlainTextEdit and I'm building a progress dialog for it when opening large files. Rather than using setText, I want to add one line of text at a time by using QTextCursor.insertText. The problem is that when I do it this way, I can undo each line that was added... is there a way to clear the undo history? Use QTextDocument::clearUndoRedoStacks . Code: editor->document()->clearUndoRedoStacks(); // default clears both See docs if you want to clear just undo. Also, it's good idea to read docs of QTextDocument (and QTextCursor) when working with the editor widgets. Lots of functionality

How to scroll QPlainTextEdit to top?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 02:49:06
I would like to automatically scroll to the top in a QPlainTextEdit widget after put in some text. How can I realize that? myTextEdit -> moveCursor (QTextCursor::Start) ; myTextEdit -> ensureCursorVisible() ; As QTextEdit inherits from QAbstractScrollArea , you can move its scrollbars: QScrollBar *vScrollBar = yourTextEdit->verticalScrollBar(); vScrollBar->triggerAction(QScrollBar::SliderToMinimum); 来源: https://stackoverflow.com/questions/7280965/how-to-scroll-qplaintextedit-to-top

Transparently get backspace event in PyQt

耗尽温柔 提交于 2019-12-02 00:54:47
I want to detect when backspace is pressed in a QPlainTextEdit widget. I have the following code: def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Backspace: print("Backspace pressed") (in a class inherited from QPlainTextEdit) The problem is that now pressing backspace (or any other character key) does not insert the character into the text box. I could check for every key and do it that way, however, especially with large files, removing the last character could be inefficient, slow and result in messy code. Is there a better way of doing this? The keyPressEvent method of

QTextEdit vs QPlainTextEdit

半腔热情 提交于 2019-11-27 14:56:10
What's the difference between QTextEdit and QPlainTextEdit , why use one over the other? I'm coding a text editor as an exercice to learn Qt5, and now I'm wondering whether to use QTextEdit or QPlainTextEdit . So far I've only found out that you can display images in QTextEdit , but other than that they look somewhat identical to me. My text editor should support some basic syntax highlighting (probably using textChanged() signal), but that's pretty much as far as the requirements go. Google searches for "QTextEdit vs QPlainTextEdit" and "QTextEdit compared to QPlainTextEdit" didn't give me

How to append text to QPlainTextEdit without adding newline, and keep scroll at the bottom?

China☆狼群 提交于 2019-11-27 04:29:20
I need to append text to QPlainTextEdit without adding a newline to the text, but both methods appendPlainText() and appendHtml() adds actually new paragraph. I can do that manually with QTextCursor : QTextCursor text_cursor = QTextCursor(my_plain_text_edit->document()); text_cursor.movePosition(QTextCursor::End); text_cursor.insertText("string to append. "); That works, but I also need to keep scroll at bottom if it was at bottom before append. I tried to copy logic from Qt's sources, but I stuck on it, because there actually QPlainTextEditPrivate class is used, and I can't find the way to do

How to append text to QPlainTextEdit without adding newline, and keep scroll at the bottom?

允我心安 提交于 2019-11-26 12:44:55
问题 I need to append text to QPlainTextEdit without adding a newline to the text, but both methods appendPlainText() and appendHtml() adds actually new paragraph. I can do that manually with QTextCursor : QTextCursor text_cursor = QTextCursor(my_plain_text_edit->document()); text_cursor.movePosition(QTextCursor::End); text_cursor.insertText(\"string to append. \"); That works, but I also need to keep scroll at bottom if it was at bottom before append. I tried to copy logic from Qt\'s sources, but