
The popup menu’s ownership is transferred to the caller. It is called from the default contextMenuEvent() handler. This function creates the standard context menu which is shown when the user clicks on the text edit with the right mouse button. createStandardContextMenu ( ) ¶ Return type The selection can be retrieved by using the textCursor() function. If you reimplement this function, note that the ownership of the returned QMimeData object is passed to the caller. It is called when the selection needs to be encapsulated into a new QMimeData object for example, when a drag and drop operation is started, or when data is copied to the clipboard. This function returns a new MIME data object to represent the contents of the text edit’s current selection. createMimeDataFromSelection ( ) ¶ Return type copyAvailable ( b ) ¶ Parametersī – bool. Scrolls the document in order to center the cursor vertically.ĬopyAvailable(). Returns whether text can be pasted from the clipboard into the textedit.

It is called for example when during a drag operation the mouse enters this widget and it is necessary to determine whether it is possible to accept the drag. This function returns true if the contents of the MIME data object, specified by source, can be decoded and inserted into the document. canInsertFromMimeData ( source ) ¶ Parameters blockCountChanged ( newBlockCount ) ¶ Parameters This property holds the number of text blocks in the document.īy default, in an empty document, this property contains a value of 1. To select (mark) text hold down the Shift key whilst pressing one of the movement keystrokes, for example, Shift+Right Arrow will select the character to the right, and Shift+Ctrl+Right Arrow will select the word to the right, etc.īlockBoundingGeometry(). Scrolls the page horizontally (the Wheel is the mouse wheel). Moves the cursor to the beginning of the text. Moves the cursor to the beginning of the line. Moves the cursor one character to the right. Moves the cursor one character to the left. Pastes the clipboard text into text edit.ĭeletes the selected text and copies it to the clipboard. The list of key bindings which are implemented for editing:ĭeletes the character to the left of the cursor.ĭeletes the character to the right of the cursor. In addition it provides methods for undo and redo. QTextDocument emits a textChanged() signal if the text changes and it also provides a isModified() function which will return true if the text has been modified since it was either loaded or since the last call to setModified with false as argument. You can also set your own document object using setDocument(). QPlainTextEdit holds a QTextDocument object which can be retrieved using the document() method. The entire text can be selected using selectAll(). The selection can be copied to the clipboard with copy(), or cut to the clipboard with cut(). If you want to set a selection in QPlainTextEdit just create one on a QTextCursor object and then make that cursor the visible cursor using setCursor(). You can retrieve the object that corresponds with the user-visible cursor using the textCursor() method. Selection of text is handled by the QTextCursor class, which provides functionality for creating selections, retrieving the text contents or deleting selections. While QPlainTextEdit does not support complex rich text rendering with tables and floats, it does support limited paragraph-based formatting that you may need in a log viewer.Īll the information about using QPlainTextEdit as a display widget also applies here. Text can be formatted in a limited way, either using a syntax highlighter (see below), or by appending html-formatted text with appendHtml(). The scrolling can be reduced with the centerOnScroll() property, making the log viewer even faster. The combination of setMaximumBlockCount() and appendPlainText() turns QPlainTextEdit into an efficient viewer for log text. If you want to limit the total number of paragraphs in a QPlainTextEdit, as it is for example useful in a log viewer, then you can use the maximumBlockCount property. The find() function can be used to find and select a given string within the text. If you use word wrap to the widget’s width WidgetWidth, you can specify whether to break on whitespace or anywhere with setWordWrapMode(). The setLineWrapMode() function is used to specify the kind of line wrap you want, WidgetWidth or NoWrap if you don’t want any wrapping. īy default, the text edit wraps words at whitespace to fit within the text edit widget. Text can be inserted using the QTextCursor class or using the convenience functions insertPlainText(), appendPlainText() or paste(). The text is set or replaced using setPlainText() which deletes the existing text and replaces it with the text passed to setPlainText().
