Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QTextEdit Class Reference

The QTextEdit class provides a widget that is used to edit and display both plain and rich text. More...

#include <qtextedit.h>

+ Inheritance diagram for QTextEdit:
+ Collaboration diagram for QTextEdit:

Classes

class  ExtraSelection
 The QTextEdit::ExtraSelection structure provides a way of specifying a character format for a given selection in a document. More...
 

Public Types

enum  LineWrapMode { NoWrap , WidgetWidth , FixedPixelWidth , FixedColumnWidth }
 \value NoWrap \value WidgetWidth \value FixedPixelWidth \value FixedColumnWidth More...
 
enum  AutoFormattingFlag { AutoNone = 0 , AutoBulletList = 0x00000001 , AutoAll = 0xffffffff }
 \value AutoNone Don't do any automatic formatting. More...
 

Public Slots

void setFontPointSize (qreal s)
 Sets the point size of the current format to s.
 
void setFontFamily (const QString &fontFamily)
 Sets the font family of the current format to fontFamily.
 
void setFontWeight (int w)
 Sets the font weight of the current format to the given weight, where the value used is in the range defined by the QFont::Weight enum.
 
void setFontUnderline (bool b)
 If underline is true, sets the current format to underline; otherwise sets the current format to non-underline.
 
void setFontItalic (bool b)
 If italic is true, sets the current format to italic; otherwise sets the current format to non-italic.
 
void setTextColor (const QColor &c)
 Sets the text color of the current format to c.
 
void setTextBackgroundColor (const QColor &c)
 
void setCurrentFont (const QFont &f)
 Sets the font of the current format to f.
 
void setAlignment (Qt::Alignment a)
 Sets the alignment of the current paragraph to a.
 
void setPlainText (const QString &text)
 Changes the text of the text edit to the string text.
 
void setHtml (const QString &text)
 
void setText (const QString &text)
 
void cut ()
 Copies the selected text to the clipboard and deletes it from the text edit.
 
void copy ()
 Copies any selected text to the clipboard.
 
void paste ()
 Pastes the text from the clipboard into the text edit at the current cursor position.
 
void undo ()
 
void redo ()
 
void clear ()
 Deletes all the text in the text edit.
 
void selectAll ()
 Selects all text.
 
void insertPlainText (const QString &text)
 Convenience slot that inserts text at the current cursor position.
 
void insertHtml (const QString &text)
 Convenience slot that inserts text which is assumed to be of html formatting at the current cursor position.
 
void append (const QString &text)
 Appends a new paragraph with text to the end of the text edit.
 
void scrollToAnchor (const QString &name)
 Scrolls the text edit so that the anchor with the given name is visible; does nothing if the name is empty, or is already visible, or isn't found.
 
void zoomIn (int range=1)
 Zooms in on the text by making the base font size range points larger and recalculating all font sizes to be the new size.
 
void zoomOut (int range=1)
 Zooms out on the text by making the base font size range points smaller and recalculating all font sizes to be the new size.
 

Signals

void textChanged ()
 This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied.
 
void undoAvailable (bool b)
 This signal is emitted whenever undo operations become available (available is true) or unavailable (available is false).
 
void redoAvailable (bool b)
 This signal is emitted whenever redo operations become available (available is true) or unavailable (available is false).
 
void currentCharFormatChanged (const QTextCharFormat &format)
 This signal is emitted if the current character format has changed, for example caused by a change of the cursor position.
 
void copyAvailable (bool b)
 This signal is emitted when text is selected or de-selected in the text edit.
 
void selectionChanged ()
 This signal is emitted whenever the selection changes.
 
void cursorPositionChanged ()
 This signal is emitted whenever the position of the cursor changed.
 

Public Member Functions

 QTextEdit (QWidget *parent=nullptr)
 Constructs an empty QTextEdit with parent parent.
 
 QTextEdit (const QString &text, QWidget *parent=nullptr)
 Constructs a QTextEdit with parent parent.
 
virtual ~QTextEdit ()
 Destructor.
 
void setDocument (QTextDocument *document)
 
QTextDocumentdocument () const
 
void setPlaceholderText (const QString &placeholderText)
 
QString placeholderText () const
 
void setTextCursor (const QTextCursor &cursor)
 Sets the visible cursor.
 
QTextCursor textCursor () const
 Returns a copy of the QTextCursor that represents the currently visible cursor.
 
bool isReadOnly () const
 
void setReadOnly (bool ro)
 
void setTextInteractionFlags (Qt::TextInteractionFlags flags)
 
Qt::TextInteractionFlags textInteractionFlags () const
 
qreal fontPointSize () const
 Returns the point size of the font of the current format.
 
QString fontFamily () const
 Returns the font family of the current format.
 
int fontWeight () const
 Returns the font weight of the current format.
 
bool fontUnderline () const
 Returns true if the font of the current format is underlined; otherwise returns false.
 
bool fontItalic () const
 Returns true if the font of the current format is italic; otherwise returns false.
 
QColor textColor () const
 Returns the text color of the current format.
 
QColor textBackgroundColor () const
 
QFont currentFont () const
 Returns the font of the current format.
 
Qt::Alignment alignment () const
 Returns the alignment of the current paragraph.
 
void mergeCurrentCharFormat (const QTextCharFormat &modifier)
 Merges the properties specified in modifier into the current character format by calling QTextCursor::mergeCharFormat on the editor's cursor.
 
void setCurrentCharFormat (const QTextCharFormat &format)
 Sets the char format that is be used when inserting new text to format by calling QTextCursor::setCharFormat() on the editor's cursor.
 
QTextCharFormat currentCharFormat () const
 Returns the char format that is used when inserting new text.
 
AutoFormatting autoFormatting () const
 
void setAutoFormatting (AutoFormatting features)
 
bool tabChangesFocus () const
 
void setTabChangesFocus (bool b)
 
void setDocumentTitle (const QString &title)
 
QString documentTitle () const
 
bool isUndoRedoEnabled () const
 
void setUndoRedoEnabled (bool enable)
 
LineWrapMode lineWrapMode () const
 
void setLineWrapMode (LineWrapMode mode)
 
int lineWrapColumnOrWidth () const
 
void setLineWrapColumnOrWidth (int w)
 
QTextOption::WrapMode wordWrapMode () const
 the mode QTextEdit will use when wrapping text by words
 
void setWordWrapMode (QTextOption::WrapMode policy)
 
bool find (const QString &exp, QTextDocument::FindFlags options=QTextDocument::FindFlags())
 Finds the next occurrence of the string, exp, using the given options.
 
QString toPlainText () const
 QString QTextEdit::toPlainText() const.
 
QString toHtml () const
 
void ensureCursorVisible ()
 Ensures that the cursor is visible by scrolling the text edit if necessary.
 
virtual Q_INVOKABLE QVariant loadResource (int type, const QUrl &name)
 Loads the resource specified by the given type and name.
 
QMenucreateStandardContextMenu ()
 \reimp
 
QMenucreateStandardContextMenu (const QPoint &position)
 
QTextCursor cursorForPosition (const QPoint &pos) const
 returns a QTextCursor at position pos (in viewport coordinates).
 
QRect cursorRect (const QTextCursor &cursor) const
 returns a rectangle (in viewport coordinates) that includes the cursor.
 
QRect cursorRect () const
 returns a rectangle (in viewport coordinates) that includes the cursor of the text edit.
 
QString anchorAt (const QPoint &pos) const
 Returns the reference of the anchor at position pos, or an empty string if no anchor exists at that point.
 
bool overwriteMode () const
 
void setOverwriteMode (bool overwrite)
 
qreal tabStopDistance () const
 
void setTabStopDistance (qreal distance)
 
int cursorWidth () const
 
void setCursorWidth (int width)
 
bool acceptRichText () const
 
void setAcceptRichText (bool accept)
 
void setExtraSelections (const QList< ExtraSelection > &selections)
 \variable QTextEdit::ExtraSelection::cursor A cursor that contains a selection in a QTextDocument
 
QList< ExtraSelectionextraSelections () const
 
void moveCursor (QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode=QTextCursor::MoveAnchor)
 
bool canPaste () const
 
void print (QPagedPaintDevice *printer) const
 
QVariant inputMethodQuery (Qt::InputMethodQuery property) const override
 \reimp
 
Q_INVOKABLE QVariant inputMethodQuery (Qt::InputMethodQuery query, QVariant argument) const
 

Protected Member Functions

virtual bool event (QEvent *e) override
 
virtual void timerEvent (QTimerEvent *e) override
 
virtual void keyPressEvent (QKeyEvent *e) override
 \reimp
 
virtual void keyReleaseEvent (QKeyEvent *e) override
 \reimp
 
virtual void resizeEvent (QResizeEvent *e) override
 \reimp
 
virtual void paintEvent (QPaintEvent *e) override
 This event handler can be reimplemented in a subclass to receive paint events passed in event.
 
virtual void mousePressEvent (QMouseEvent *e) override
 \reimp
 
virtual void mouseMoveEvent (QMouseEvent *e) override
 \reimp
 
virtual void mouseReleaseEvent (QMouseEvent *e) override
 \reimp
 
virtual void mouseDoubleClickEvent (QMouseEvent *e) override
 \reimp
 
virtual bool focusNextPrevChild (bool next) override
 \reimp
 
virtual void contextMenuEvent (QContextMenuEvent *e) override
 Shows the standard context menu created with createStandardContextMenu().
 
virtual void focusInEvent (QFocusEvent *e) override
 \reimp
 
virtual void focusOutEvent (QFocusEvent *e) override
 \reimp
 
virtual void showEvent (QShowEvent *) override
 \reimp
 
virtual void changeEvent (QEvent *e) override
 \reimp
 
virtual QMimeDatacreateMimeDataFromSelection () const
 This function returns a new MIME data object to represent the contents of the text edit's current selection.
 
virtual bool canInsertFromMimeData (const QMimeData *source) const
 This function returns true if the contents of the MIME data object, specified by source, can be decoded and inserted into the document.
 
virtual void insertFromMimeData (const QMimeData *source)
 This function inserts the contents of the MIME data object, specified by source, into the text edit at the current cursor position.
 
virtual void inputMethodEvent (QInputMethodEvent *) override
 \reimp
 
 QTextEdit (QTextEditPrivate &dd, QWidget *parent)
 
virtual void scrollContentsBy (int dx, int dy) override
 \reimp
 
virtual void doSetTextCursor (const QTextCursor &cursor)
 
void zoomInF (float range)
 

Properties

AutoFormatting autoFormatting
 the enabled set of auto formatting features
 
bool tabChangesFocus
 whether \uicontrol Tab changes focus or is accepted as input
 
QString documentTitle
 the title of the document parsed from the text.
 
bool undoRedoEnabled
 whether undo and redo are enabled.
 
LineWrapMode lineWrapMode
 the line wrap mode
 
int lineWrapColumnOrWidth
 the position (in pixels or columns depending on the wrap mode) where text will be wrapped
 
bool readOnly
 whether the text edit is read-only
 
QString html
 This property provides an HTML interface to the text of the text edit.
 
QString plainText
 the text editor's contents as plain text.
 
bool overwriteMode
 whether text entered by the user will overwrite existing text
 
qreal tabStopDistance
 the tab stop distance in pixels
 
bool acceptRichText
 whether the text edit accepts rich text insertions by the user
 
int cursorWidth
 
Qt::TextInteractionFlags textInteractionFlags
 
QTextDocumentdocument
 the underlying document of the text editor.
 
QString placeholderText
 the editor placeholder text
 

Friends

class QTextEditControl
 
class QTextDocument
 
class QWidgetTextControl
 

Detailed Description

The QTextEdit class provides a widget that is used to edit and display both plain and rich text.

\inmodule QtWidgets

Definition at line 26 of file qtextedit.h.

Member Enumeration Documentation

◆ AutoFormattingFlag

\value AutoNone Don't do any automatic formatting.

\value AutoBulletList Automatically create bullet lists (e.g. when the user enters an asterisk ('*') in the left most column, or presses Enter in an existing list item. \value AutoAll Apply all automatic formatting. Currently only automatic bullet lists are supported.

Enumerator
AutoNone 
AutoBulletList 
AutoAll 

Definition at line 62 of file qtextedit.h.

◆ LineWrapMode

\value NoWrap \value WidgetWidth \value FixedPixelWidth \value FixedColumnWidth

Enumerator
NoWrap 
WidgetWidth 
FixedPixelWidth 
FixedColumnWidth 

Definition at line 54 of file qtextedit.h.

Constructor & Destructor Documentation

◆ QTextEdit() [1/3]

QTextEdit::QTextEdit ( QWidget * parent = nullptr)
explicit

Constructs an empty QTextEdit with parent parent.

Definition at line 613 of file qtextedit.cpp.

◆ QTextEdit() [2/3]

QTextEdit::QTextEdit ( const QString & text,
QWidget * parent = nullptr )
explicit

Constructs a QTextEdit with parent parent.

The text edit will display the text text. The text is interpreted as html.

Definition at line 634 of file qtextedit.cpp.

◆ ~QTextEdit()

QTextEdit::~QTextEdit ( )
virtual

Destructor.

Definition at line 646 of file qtextedit.cpp.

◆ QTextEdit() [3/3]

QTextEdit::QTextEdit ( QTextEditPrivate & dd,
QWidget * parent )
protected

Definition at line 623 of file qtextedit.cpp.

Member Function Documentation

◆ acceptRichText()

bool QTextEdit::acceptRichText ( ) const

Definition at line 2117 of file qtextedit.cpp.

◆ alignment()

Qt::Alignment QTextEdit::alignment ( ) const

Returns the alignment of the current paragraph.

See also
setAlignment()

Definition at line 772 of file qtextedit.cpp.

◆ anchorAt()

QString QTextEdit::anchorAt ( const QPoint & pos) const

Returns the reference of the anchor at position pos, or an empty string if no anchor exists at that point.

Definition at line 2025 of file qtextedit.cpp.

◆ append

void QTextEdit::append ( const QString & text)
slot

Appends a new paragraph with text to the end of the text edit.

Note
The new paragraph appended will have the same character format and block format as the current paragraph, determined by the position of the cursor.
See also
currentCharFormat(), QTextCursor::blockFormat()

Definition at line 2698 of file qtextedit.cpp.

◆ autoFormatting()

QTextEdit::AutoFormatting QTextEdit::autoFormatting ( ) const

Definition at line 2326 of file qtextedit.cpp.

◆ canInsertFromMimeData()

bool QTextEdit::canInsertFromMimeData ( const QMimeData * source) const
protectedvirtual

This function returns true if the contents of the MIME data object, specified by source, can be decoded and inserted into the document.

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 and drop operation.

Reimplement this function to enable drag and drop support for additional MIME types.

Reimplemented in TextEdit.

Definition at line 2201 of file qtextedit.cpp.

◆ canPaste()

bool QTextEdit::canPaste ( ) const
Since
4.2 Returns whether text can be pasted from the clipboard into the textedit.

Definition at line 2455 of file qtextedit.cpp.

◆ changeEvent()

void QTextEdit::changeEvent ( QEvent * e)
overrideprotectedvirtual

\reimp

Definition at line 1912 of file qtextedit.cpp.

◆ clear

void QTextEdit::clear ( )
slot

Deletes all the text in the text edit.

Notes: \list

See also
cut(), setPlainText(), setHtml()

Definition at line 1063 of file qtextedit.cpp.

◆ contextMenuEvent()

void QTextEdit::contextMenuEvent ( QContextMenuEvent * event)
overrideprotectedvirtual

Shows the standard context menu created with createStandardContextMenu().

If you do not want the text edit to have a context menu, you can set its \l contextMenuPolicy to Qt::NoContextMenu. If you want to customize the context menu, reimplement this function. If you want to extend the standard context menu, reimplement this function, call createStandardContextMenu() and extend the menu returned.

Information about the event is passed in the event object.

void MyTextEdit::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *menu = createStandardContextMenu();
menu->addAction(tr("My Menu Item"));
//...
menu->exec(event->globalPos());
delete menu;
}

Reimplemented in LogViewer, qdesigner_internal::HtmlTextEdit, and qdesigner_internal::HtmlTextEdit.

Definition at line 1736 of file qtextedit.cpp.

◆ copy

void QTextEdit::copy ( )
slot

Copies any selected text to the clipboard.

See also
copyAvailable()

Definition at line 1024 of file qtextedit.cpp.

◆ copyAvailable

void QTextEdit::copyAvailable ( bool yes)
signal

This signal is emitted when text is selected or de-selected in the text edit.

When text is selected this signal will be emitted with yes set to true. If no text has been selected or if the selected text is de-selected this signal is emitted with yes set to false.

If yes is true then copy() can be used to copy the selection to the clipboard. If yes is false then copy() does nothing.

See also
selectionChanged()

◆ createMimeDataFromSelection()

QMimeData * QTextEdit::createMimeDataFromSelection ( ) const
protectedvirtual

This function returns a new MIME data object to represent the contents of the text edit's current selection.

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.

If you reimplement this function, note that the ownership of the returned QMimeData object is passed to the caller. The selection can be retrieved by using the textCursor() function.

Definition at line 2186 of file qtextedit.cpp.

◆ createStandardContextMenu() [1/2]

QMenu * QTextEdit::createStandardContextMenu ( )

\reimp

This function creates the standard context menu which is shown when the user clicks on the text edit with the right mouse button. It is called from the default contextMenuEvent() handler. The popup menu's ownership is transferred to the caller.

We recommend that you use the createStandardContextMenu(QPoint) version instead which will enable the actions that are sensitive to where the user clicked.

Definition at line 1961 of file qtextedit.cpp.

◆ createStandardContextMenu() [2/2]

QMenu * QTextEdit::createStandardContextMenu ( const QPoint & position)
Since
4.4 This function creates the standard context menu which is shown when the user clicks on the text edit with the right mouse button. It is called from the default contextMenuEvent() handler and it takes the position in document coordinates where the mouse click was. This can enable actions that are sensitive to the position where the user clicked. The popup menu's ownership is transferred to the caller.

Definition at line 1977 of file qtextedit.cpp.

◆ currentCharFormat()

QTextCharFormat QTextEdit::currentCharFormat ( ) const

Returns the char format that is used when inserting new text.

Definition at line 2308 of file qtextedit.cpp.

◆ currentCharFormatChanged

void QTextEdit::currentCharFormatChanged ( const QTextCharFormat & f)
signal

This signal is emitted if the current character format has changed, for example caused by a change of the cursor position.

The new format is f.

See also
setCurrentCharFormat()

◆ currentFont()

QFont QTextEdit::currentFont ( ) const

Returns the font of the current format.

See also
setCurrentFont(), setFontFamily(), setFontPointSize()

Definition at line 744 of file qtextedit.cpp.

◆ cursorForPosition()

QTextCursor QTextEdit::cursorForPosition ( const QPoint & pos) const

returns a QTextCursor at position pos (in viewport coordinates).

Definition at line 1987 of file qtextedit.cpp.

◆ cursorPositionChanged

void QTextEdit::cursorPositionChanged ( )
signal

This signal is emitted whenever the position of the cursor changed.

◆ cursorRect() [1/2]

QRect QTextEdit::cursorRect ( ) const

returns a rectangle (in viewport coordinates) that includes the cursor of the text edit.

Definition at line 2012 of file qtextedit.cpp.

◆ cursorRect() [2/2]

QRect QTextEdit::cursorRect ( const QTextCursor & cursor) const

returns a rectangle (in viewport coordinates) that includes the cursor.

Definition at line 1997 of file qtextedit.cpp.

◆ cursorWidth()

int QTextEdit::cursorWidth ( ) const

Definition at line 2094 of file qtextedit.cpp.

◆ cut

void QTextEdit::cut ( )
slot

Copies the selected text to the clipboard and deletes it from the text edit.

If there is no selected text nothing happens.

See also
copy(), paste()

Definition at line 1012 of file qtextedit.cpp.

◆ document()

QTextDocument * QTextEdit::document ( ) const

Definition at line 795 of file qtextedit.cpp.

◆ documentTitle()

QString QTextEdit::documentTitle ( ) const
inline

Definition at line 113 of file qtextedit.h.

◆ doSetTextCursor()

void QTextEdit::doSetTextCursor ( const QTextCursor & cursor)
protectedvirtual

This provides a hook for subclasses to intercept cursor changes.

Definition at line 844 of file qtextedit.cpp.

◆ ensureCursorVisible()

void QTextEdit::ensureCursorVisible ( )

Ensures that the cursor is visible by scrolling the text edit if necessary.

Definition at line 2712 of file qtextedit.cpp.

◆ event()

bool QTextEdit::event ( QEvent * e)
overrideprotectedvirtual

Reimplemented in QTextBrowser.

Definition at line 1084 of file qtextedit.cpp.

◆ extraSelections()

QList< QTextEdit::ExtraSelection > QTextEdit::extraSelections ( ) const
Since
4.2 Returns previously set extra selections.
See also
setExtraSelections()

Definition at line 2170 of file qtextedit.cpp.

◆ find()

bool QTextEdit::find ( const QString & exp,
QTextDocument::FindFlags options = QTextDocument::FindFlags() )

Finds the next occurrence of the string, exp, using the given options.

Returns true if exp was found and changes the cursor to select the match; otherwise returns false.

Since
5.13 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Finds the next occurrence, matching the regular expression, exp, using the given options.

Returns true if a match was found and changes the cursor to select the match; otherwise returns false.

Warning
For historical reasons, the case sensitivity option set on exp is ignored. Instead, the options are used to determine if the search is case sensitive or not.

Definition at line 2593 of file qtextedit.cpp.

◆ focusInEvent()

void QTextEdit::focusInEvent ( QFocusEvent * e)
overrideprotectedvirtual

\reimp

Definition at line 1876 of file qtextedit.cpp.

◆ focusNextPrevChild()

bool QTextEdit::focusNextPrevChild ( bool next)
overrideprotectedvirtual

\reimp

Reimplemented in QTextBrowser.

Definition at line 1712 of file qtextedit.cpp.

◆ focusOutEvent()

void QTextEdit::focusOutEvent ( QFocusEvent * e)
overrideprotectedvirtual

\reimp

Reimplemented in QTextBrowser.

Definition at line 1888 of file qtextedit.cpp.

◆ fontFamily()

QString QTextEdit::fontFamily ( ) const

Returns the font family of the current format.

See also
setFontFamily(), setCurrentFont(), setFontPointSize()

Definition at line 666 of file qtextedit.cpp.

◆ fontItalic()

bool QTextEdit::fontItalic ( ) const

Returns true if the font of the current format is italic; otherwise returns false.

See also
setFontItalic()

Definition at line 701 of file qtextedit.cpp.

◆ fontPointSize()

qreal QTextEdit::fontPointSize ( ) const

Returns the point size of the font of the current format.

See also
setFontFamily(), setCurrentFont(), setFontPointSize()

Definition at line 655 of file qtextedit.cpp.

◆ fontUnderline()

bool QTextEdit::fontUnderline ( ) const

Returns true if the font of the current format is underlined; otherwise returns false.

See also
setFontUnderline()

Definition at line 689 of file qtextedit.cpp.

◆ fontWeight()

int QTextEdit::fontWeight ( ) const

Returns the font weight of the current format.

See also
setFontWeight(), setCurrentFont(), setFontPointSize(), QFont::Weight

Definition at line 677 of file qtextedit.cpp.

◆ inputMethodEvent()

void QTextEdit::inputMethodEvent ( QInputMethodEvent * e)
overrideprotectedvirtual

\reimp

Definition at line 1788 of file qtextedit.cpp.

◆ inputMethodQuery() [1/2]

QVariant QTextEdit::inputMethodQuery ( Qt::InputMethodQuery property) const
override

\reimp

Definition at line 1818 of file qtextedit.cpp.

◆ inputMethodQuery() [2/2]

QVariant QTextEdit::inputMethodQuery ( Qt::InputMethodQuery query,
QVariant argument ) const

Definition at line 1825 of file qtextedit.cpp.

◆ insertFromMimeData()

void QTextEdit::insertFromMimeData ( const QMimeData * source)
protectedvirtual

This function inserts the contents of the MIME data object, specified by source, into the text edit at the current cursor position.

It is called whenever text is inserted as the result of a clipboard paste operation, or when the text edit accepts data from a drag and drop operation.

Reimplement this function to enable drag and drop support for additional MIME types.

Reimplemented in TextEdit.

Definition at line 2216 of file qtextedit.cpp.

◆ insertHtml

void QTextEdit::insertHtml ( const QString & text)
slot

Convenience slot that inserts text which is assumed to be of html formatting at the current cursor position.

It is equivalent to:

edit->textCursor().insertHtml(fragment);
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:595
Note
When using this function with a style sheet, the style sheet will only apply to the current block in the document. In order to apply a style sheet throughout a document, use QTextDocument::setDefaultStyleSheet() instead.

Definition at line 2366 of file qtextedit.cpp.

◆ insertPlainText

void QTextEdit::insertPlainText ( const QString & text)
slot

Convenience slot that inserts text at the current cursor position.

It is equivalent to

edit->textCursor().insertText(text);

Definition at line 2346 of file qtextedit.cpp.

◆ isReadOnly()

bool QTextEdit::isReadOnly ( ) const

Definition at line 2232 of file qtextedit.cpp.

◆ isUndoRedoEnabled()

bool QTextEdit::isUndoRedoEnabled ( ) const
inline

Definition at line 116 of file qtextedit.h.

◆ keyPressEvent()

void QTextEdit::keyPressEvent ( QKeyEvent * e)
overrideprotectedvirtual

\reimp

Reimplemented in QTextBrowser.

Definition at line 1294 of file qtextedit.cpp.

◆ keyReleaseEvent()

void QTextEdit::keyReleaseEvent ( QKeyEvent * e)
overrideprotectedvirtual

\reimp

Definition at line 1448 of file qtextedit.cpp.

◆ lineWrapColumnOrWidth()

int QTextEdit::lineWrapColumnOrWidth ( ) const

Definition at line 2551 of file qtextedit.cpp.

◆ lineWrapMode()

QTextEdit::LineWrapMode QTextEdit::lineWrapMode ( ) const

Definition at line 2520 of file qtextedit.cpp.

◆ loadResource()

QVariant QTextEdit::loadResource ( int type,
const QUrl & name )
virtual

Loads the resource specified by the given type and name.

This function is an extension of QTextDocument::loadResource().

See also
QTextDocument::loadResource()

Reimplemented in AboutLabel, and QTextBrowser.

Definition at line 1486 of file qtextedit.cpp.

◆ mergeCurrentCharFormat()

void QTextEdit::mergeCurrentCharFormat ( const QTextCharFormat & modifier)

Merges the properties specified in modifier into the current character format by calling QTextCursor::mergeCharFormat on the editor's cursor.

If the editor has a selection then the properties of modifier are directly applied to the selection.

See also
QTextCursor::mergeCharFormat()

Definition at line 2287 of file qtextedit.cpp.

◆ mouseDoubleClickEvent()

void QTextEdit::mouseDoubleClickEvent ( QMouseEvent * e)
overrideprotectedvirtual

\reimp

Definition at line 1704 of file qtextedit.cpp.

◆ mouseMoveEvent()

void QTextEdit::mouseMoveEvent ( QMouseEvent * e)
overrideprotectedvirtual

\reimp

Reimplemented in QTextBrowser.

Definition at line 1670 of file qtextedit.cpp.

◆ mousePressEvent()

void QTextEdit::mousePressEvent ( QMouseEvent * e)
overrideprotectedvirtual

\reimp

Reimplemented in QTextBrowser.

Definition at line 1658 of file qtextedit.cpp.

◆ mouseReleaseEvent()

void QTextEdit::mouseReleaseEvent ( QMouseEvent * e)
overrideprotectedvirtual

\reimp

Reimplemented in QTextBrowser.

Definition at line 1689 of file qtextedit.cpp.

◆ moveCursor()

void QTextEdit::moveCursor ( QTextCursor::MoveOperation operation,
QTextCursor::MoveMode mode = QTextCursor::MoveAnchor )
Since
4.2 Moves the cursor by performing the given operation.

If mode is QTextCursor::KeepAnchor, the cursor selects the text it moves over. This is the same effect that the user achieves when they hold down the Shift key and move the cursor with the cursor keys.

See also
QTextCursor::movePosition()

Definition at line 2445 of file qtextedit.cpp.

◆ overwriteMode()

bool QTextEdit::overwriteMode ( ) const

Definition at line 2046 of file qtextedit.cpp.

◆ paintEvent()

void QTextEdit::paintEvent ( QPaintEvent * event)
overrideprotectedvirtual

This event handler can be reimplemented in a subclass to receive paint events passed in event.

It is usually unnecessary to reimplement this function in a subclass of QTextEdit.

Note
If you create a QPainter, it must operate on the \l{QAbstractScrollArea::}{viewport()}.
Warning
The underlying text document must not be modified from within a reimplementation of this function.

Reimplemented in QTextBrowser.

Definition at line 1633 of file qtextedit.cpp.

◆ paste

void QTextEdit::paste ( )
slot

Pastes the text from the clipboard into the text edit at the current cursor position.

If there is no text in the clipboard nothing happens.

To change the behavior of this function, i.e. to modify what QTextEdit can paste and how it is being pasted, reimplement the virtual canInsertFromMimeData() and insertFromMimeData() functions.

See also
cut(), copy()

Definition at line 1044 of file qtextedit.cpp.

◆ placeholderText()

QString QTextEdit::placeholderText ( ) const

Definition at line 814 of file qtextedit.cpp.

◆ print()

void QTextEdit::print ( QPagedPaintDevice * printer) const
Since
4.3 Convenience function to print the text edit's document to the given printer. This is equivalent to calling the print method on the document directly except that this function also supports QPrinter::Selection as print range.
See also
QTextDocument::print()

Definition at line 2470 of file qtextedit.cpp.

◆ redo

void QTextEdit::redo ( )
slot
Since
4.2

Redoes the last operation.

If there is no operation to redo, i.e. there is no redo step in the undo/redo history, nothing happens.

See also
undo()

Definition at line 984 of file qtextedit.cpp.

◆ redoAvailable

void QTextEdit::redoAvailable ( bool b)
signal

This signal is emitted whenever redo operations become available (available is true) or unavailable (available is false).

◆ resizeEvent()

void QTextEdit::resizeEvent ( QResizeEvent * e)
overrideprotectedvirtual

\reimp

Definition at line 1495 of file qtextedit.cpp.

◆ scrollContentsBy()

void QTextEdit::scrollContentsBy ( int dx,
int dy )
overrideprotectedvirtual

\reimp

Definition at line 1807 of file qtextedit.cpp.

◆ scrollToAnchor

void QTextEdit::scrollToAnchor ( const QString & name)
slot

Scrolls the text edit so that the anchor with the given name is visible; does nothing if the name is empty, or is already visible, or isn't found.

Definition at line 2378 of file qtextedit.cpp.

◆ selectAll

void QTextEdit::selectAll ( )
slot

Selects all text.

See also
copy(), cut(), textCursor()

Definition at line 1076 of file qtextedit.cpp.

◆ selectionChanged

void QTextEdit::selectionChanged ( )
signal

This signal is emitted whenever the selection changes.

See also
copyAvailable()

◆ setAcceptRichText()

void QTextEdit::setAcceptRichText ( bool accept)

Definition at line 2123 of file qtextedit.cpp.

◆ setAlignment

void QTextEdit::setAlignment ( Qt::Alignment a)
slot

Sets the alignment of the current paragraph to a.

Valid alignments are Qt::AlignLeft, Qt::AlignRight, Qt::AlignJustify and Qt::AlignCenter (which centers horizontally).

Definition at line 756 of file qtextedit.cpp.

◆ setAutoFormatting()

void QTextEdit::setAutoFormatting ( AutoFormatting features)

Definition at line 2332 of file qtextedit.cpp.

◆ setCurrentCharFormat()

void QTextEdit::setCurrentCharFormat ( const QTextCharFormat & format)

Sets the char format that is be used when inserting new text to format by calling QTextCursor::setCharFormat() on the editor's cursor.

If the editor has a selection then the char format is directly applied to the selection.

Definition at line 2299 of file qtextedit.cpp.

◆ setCurrentFont

void QTextEdit::setCurrentFont ( const QFont & f)
slot

Sets the font of the current format to f.

See also
currentFont(), setFontPointSize(), setFontFamily()

Definition at line 961 of file qtextedit.cpp.

◆ setCursorWidth()

void QTextEdit::setCursorWidth ( int width)

Definition at line 2100 of file qtextedit.cpp.

◆ setDocument()

void QTextEdit::setDocument ( QTextDocument * document)

Definition at line 787 of file qtextedit.cpp.

◆ setDocumentTitle()

void QTextEdit::setDocumentTitle ( const QString & title)
inline

Definition at line 111 of file qtextedit.h.

◆ setExtraSelections()

void QTextEdit::setExtraSelections ( const QList< ExtraSelection > & selections)

\variable QTextEdit::ExtraSelection::cursor A cursor that contains a selection in a QTextDocument

\variable QTextEdit::ExtraSelection::format A format that is used to specify a foreground or background brush/color for the selection.

Since
4.2 This function allows temporarily marking certain regions in the document with a given color, specified as selections. This can be useful for example in a programming editor to mark a whole line of text with a given background color to indicate the existence of a breakpoint.
See also
QTextEdit::ExtraSelection, extraSelections()

Definition at line 2158 of file qtextedit.cpp.

◆ setFontFamily

void QTextEdit::setFontFamily ( const QString & fontFamily)
slot

Sets the font family of the current format to fontFamily.

See also
fontFamily(), setCurrentFont()

Definition at line 866 of file qtextedit.cpp.

◆ setFontItalic

void QTextEdit::setFontItalic ( bool italic)
slot

If italic is true, sets the current format to italic; otherwise sets the current format to non-italic.

See also
fontItalic()

Definition at line 923 of file qtextedit.cpp.

◆ setFontPointSize

void QTextEdit::setFontPointSize ( qreal s)
slot

Sets the point size of the current format to s.

Note that if s is zero or negative, the behavior of this function is not defined.

See also
fontPointSize(), setCurrentFont(), setFontFamily()

Definition at line 881 of file qtextedit.cpp.

◆ setFontUnderline

void QTextEdit::setFontUnderline ( bool underline)
slot

If underline is true, sets the current format to underline; otherwise sets the current format to non-underline.

See also
fontUnderline()

Definition at line 910 of file qtextedit.cpp.

◆ setFontWeight

void QTextEdit::setFontWeight ( int weight)
slot

Sets the font weight of the current format to the given weight, where the value used is in the range defined by the QFont::Weight enum.

See also
fontWeight(), setCurrentFont(), setFontFamily()

Definition at line 897 of file qtextedit.cpp.

◆ setHtml

void QTextEdit::setHtml ( const QString & text)
slot

Definition at line 1226 of file qtextedit.cpp.

◆ setLineWrapColumnOrWidth()

void QTextEdit::setLineWrapColumnOrWidth ( int w)

Definition at line 2557 of file qtextedit.cpp.

◆ setLineWrapMode()

void QTextEdit::setLineWrapMode ( LineWrapMode mode)

Definition at line 2526 of file qtextedit.cpp.

◆ setOverwriteMode()

void QTextEdit::setOverwriteMode ( bool overwrite)

Definition at line 2052 of file qtextedit.cpp.

◆ setPlaceholderText()

void QTextEdit::setPlaceholderText ( const QString & placeholderText)

Definition at line 820 of file qtextedit.cpp.

◆ setPlainText

void QTextEdit::setPlainText ( const QString & text)
slot

Changes the text of the text edit to the string text.

Any previous text is removed.

Notes: \list

  • text is interpreted as plain text.
  • The undo/redo history is also cleared.
  • currentCharFormat() is reset, unless textCursor() is already at the beginning of the document. \endlist
See also
toPlainText()

Definition at line 1183 of file qtextedit.cpp.

◆ setReadOnly()

void QTextEdit::setReadOnly ( bool ro)

Definition at line 2238 of file qtextedit.cpp.

◆ setTabChangesFocus()

void QTextEdit::setTabChangesFocus ( bool b)

Definition at line 2492 of file qtextedit.cpp.

◆ setTabStopDistance()

void QTextEdit::setTabStopDistance ( qreal distance)

Definition at line 2078 of file qtextedit.cpp.

◆ setText

void QTextEdit::setText ( const QString & text)
slot
Since
4.2

Sets the text edit's text. The text can be plain text or HTML and the text edit will try to guess the right format.

Use setHtml() or setPlainText() directly to avoid text edit's guessing.

See also
toPlainText(), toHtml()

Definition at line 2675 of file qtextedit.cpp.

◆ setTextBackgroundColor

void QTextEdit::setTextBackgroundColor ( const QColor & c)
slot
Since
4.4

Sets the text background color of the current format to c.

See also
textBackgroundColor()

Definition at line 949 of file qtextedit.cpp.

◆ setTextColor

void QTextEdit::setTextColor ( const QColor & c)
slot

Sets the text color of the current format to c.

See also
textColor()

Definition at line 935 of file qtextedit.cpp.

◆ setTextCursor()

void QTextEdit::setTextCursor ( const QTextCursor & cursor)

Sets the visible cursor.

Definition at line 833 of file qtextedit.cpp.

◆ setTextInteractionFlags()

void QTextEdit::setTextInteractionFlags ( Qt::TextInteractionFlags flags)

Definition at line 2267 of file qtextedit.cpp.

◆ setUndoRedoEnabled()

void QTextEdit::setUndoRedoEnabled ( bool enable)
inline

Definition at line 118 of file qtextedit.h.

◆ setWordWrapMode()

void QTextEdit::setWordWrapMode ( QTextOption::WrapMode policy)

Definition at line 2579 of file qtextedit.cpp.

◆ showEvent()

void QTextEdit::showEvent ( QShowEvent * )
overrideprotectedvirtual

\reimp

Definition at line 1897 of file qtextedit.cpp.

◆ tabChangesFocus()

bool QTextEdit::tabChangesFocus ( ) const

Definition at line 2486 of file qtextedit.cpp.

◆ tabStopDistance()

qreal QTextEdit::tabStopDistance ( ) const

Definition at line 2072 of file qtextedit.cpp.

◆ textBackgroundColor()

QColor QTextEdit::textBackgroundColor ( ) const
Since
4.4

Returns the text background color of the current format.

See also
setTextBackgroundColor()

Definition at line 732 of file qtextedit.cpp.

◆ textChanged

void QTextEdit::textChanged ( )
signal

This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied.

◆ textColor()

QColor QTextEdit::textColor ( ) const

Returns the text color of the current format.

See also
setTextColor()

Definition at line 712 of file qtextedit.cpp.

◆ textCursor()

QTextCursor QTextEdit::textCursor ( ) const

Returns a copy of the QTextCursor that represents the currently visible cursor.

Note that changes on the returned cursor do not affect QTextEdit's cursor; use setTextCursor() to update the visible cursor.

Definition at line 855 of file qtextedit.cpp.

◆ textInteractionFlags()

Qt::TextInteractionFlags QTextEdit::textInteractionFlags ( ) const

Definition at line 2273 of file qtextedit.cpp.

◆ timerEvent()

void QTextEdit::timerEvent ( QTimerEvent * e)
overrideprotectedvirtual

Definition at line 1125 of file qtextedit.cpp.

◆ toHtml()

QString QTextEdit::toHtml ( ) const

Definition at line 1233 of file qtextedit.cpp.

◆ toPlainText()

QString QTextEdit::toPlainText ( ) const

QString QTextEdit::toPlainText() const.

Returns the text of the text edit as plain text.

See also
QTextEdit::setPlainText()

Definition at line 1197 of file qtextedit.cpp.

◆ undo

void QTextEdit::undo ( )
slot
Since
4.2

Undoes the last operation.

If there is no operation to undo, i.e. there is no undo step in the undo/redo history, nothing happens.

See also
redo()

Definition at line 978 of file qtextedit.cpp.

◆ undoAvailable

void QTextEdit::undoAvailable ( bool b)
signal

This signal is emitted whenever undo operations become available (available is true) or unavailable (available is false).

◆ wordWrapMode()

QTextOption::WrapMode QTextEdit::wordWrapMode ( ) const

the mode QTextEdit will use when wrapping text by words

By default, this property is set to QTextOption::WrapAtWordBoundaryOrAnywhere.

See also
QTextOption::WrapMode

Definition at line 2573 of file qtextedit.cpp.

◆ zoomIn

void QTextEdit::zoomIn ( int range = 1)
slot

Zooms in on the text by making the base font size range points larger and recalculating all font sizes to be the new size.

This does not change the size of any images.

See also
zoomOut()

Definition at line 2403 of file qtextedit.cpp.

◆ zoomInF()

void QTextEdit::zoomInF ( float range)
protected

Definition at line 2423 of file qtextedit.cpp.

◆ zoomOut

void QTextEdit::zoomOut ( int range = 1)
slot

Zooms out on the text by making the base font size range points smaller and recalculating all font sizes to be the new size.

This does not change the size of any images.

See also
zoomIn()

Definition at line 2415 of file qtextedit.cpp.

Friends And Related Symbol Documentation

◆ QTextDocument

friend class QTextDocument
friend

Definition at line 284 of file qtextedit.h.

◆ QTextEditControl

friend class QTextEditControl
friend

Definition at line 283 of file qtextedit.h.

◆ QWidgetTextControl

friend class QWidgetTextControl
friend

Definition at line 285 of file qtextedit.h.

Property Documentation

◆ acceptRichText

bool QTextEdit::acceptRichText
readwrite

whether the text edit accepts rich text insertions by the user

Since
4.1

When this property is set to false text edit will accept only plain text input from the user. For example through clipboard or drag and drop.

This property's default is true.

Definition at line 47 of file qtextedit.h.

◆ autoFormatting

AutoFormatting QTextEdit::autoFormatting
readwrite

the enabled set of auto formatting features

The value can be any combination of the values in the AutoFormattingFlag enum. The default is AutoNone. Choose AutoAll to enable all automatic formatting.

Currently, the only automatic formatting feature provided is AutoBulletList; future versions of Qt may offer more.

Definition at line 30 of file qtextedit.h.

◆ cursorWidth

int QTextEdit::cursorWidth
readwrite
Since
4.2

This property specifies the width of the cursor in pixels. The default value is 1.

Definition at line 48 of file qtextedit.h.

◆ document

QTextDocument * QTextEdit::document
readwrite

the underlying document of the text editor.

Note
The editor {does not take ownership of the document} unless it is the document's parent object. The parent object of the provided document remains the owner of the object. If the previously assigned document is a child of the editor then it will be deleted.

Definition at line 51 of file qtextedit.h.

◆ documentTitle

QString QTextEdit::documentTitle
readwrite

the title of the document parsed from the text.

By default, for a newly-created, empty document, this property contains an empty string.

Definition at line 32 of file qtextedit.h.

◆ html

QString QTextEdit::html
readwrite

This property provides an HTML interface to the text of the text edit.

toHtml() returns the text of the text edit as html.

setHtml() changes the text of the text edit. Any previous text is removed and the undo/redo history is cleared. The input text is interpreted as rich text in html format. currentCharFormat() is also reset, unless textCursor() is already at the beginning of the document.

Note
It is the responsibility of the caller to make sure that the text is correctly decoded when a QString containing HTML is created and passed to setHtml().

By default, for a newly-created, empty document, this property contains text to describe an HTML 4.0 document with no body text.

See also
{Supported HTML Subset}, plainText

Definition at line 42 of file qtextedit.h.

◆ lineWrapColumnOrWidth

int QTextEdit::lineWrapColumnOrWidth
readwrite

the position (in pixels or columns depending on the wrap mode) where text will be wrapped

If the wrap mode is FixedPixelWidth, the value is the number of pixels from the left edge of the text edit at which text should be wrapped. If the wrap mode is FixedColumnWidth, the value is the column number (in character columns) from the left edge of the text edit at which text should be wrapped.

By default, this property contains a value of 0.

See also
lineWrapMode

Definition at line 36 of file qtextedit.h.

◆ lineWrapMode

LineWrapMode QTextEdit::lineWrapMode
readwrite

the line wrap mode

The default mode is WidgetWidth which causes words to be wrapped at the right edge of the text edit. Wrapping occurs at whitespace, keeping whole words intact. If you want wrapping to occur within words use setWordWrapMode(). If you set a wrap mode of FixedPixelWidth or FixedColumnWidth you should also call setLineWrapColumnOrWidth() with the width you want.

See also
lineWrapColumnOrWidth

Definition at line 34 of file qtextedit.h.

◆ overwriteMode

bool QTextEdit::overwriteMode
readwrite

whether text entered by the user will overwrite existing text

Since
4.1

As with many text editors, the text editor widget can be configured to insert or overwrite existing text with new text entered by the user.

If this property is true, existing text is overwritten, character-for-character by new text; otherwise, text is inserted at the cursor position, displacing existing text.

By default, this property is false (new text does not overwrite existing text).

Definition at line 45 of file qtextedit.h.

◆ placeholderText

QString QTextEdit::placeholderText
readwrite

the editor placeholder text

Since
5.2

Setting this property makes the editor display a grayed-out placeholder text as long as the document() is empty.

By default, this property contains an empty string.

See also
document()

Definition at line 52 of file qtextedit.h.

◆ plainText

QString QTextEdit::plainText
readwrite

the text editor's contents as plain text.

Since
4.3

Previous contents are removed and undo/redo history is reset when the property is set. currentCharFormat() is also reset, unless textCursor() is already at the beginning of the document.

If the text edit has another content type, it will not be replaced by plain text if you call toPlainText(). The only exception to this is the non-break space, {nbsp;}, that will be converted into standard space.

By default, for an editor with no contents, this property contains an empty string.

See also
html

Definition at line 44 of file qtextedit.h.

◆ readOnly

bool QTextEdit::readOnly
readwrite

whether the text edit is read-only

In a read-only text edit the user can only navigate through the text and select text; modifying the text is not possible.

This property's default is false.

Definition at line 37 of file qtextedit.h.

◆ tabChangesFocus

bool QTextEdit::tabChangesFocus
readwrite

whether \uicontrol Tab changes focus or is accepted as input

In some occasions text edits should not allow the user to input tabulators or change indentation using the \uicontrol Tab key, as this breaks the focus chain. The default is false.

Definition at line 31 of file qtextedit.h.

◆ tabStopDistance

qreal QTextEdit::tabStopDistance
readwrite

the tab stop distance in pixels

Since
5.10

By default, this property contains a value of 80 pixels.

Do not set a value less than the \l {QFontMetrics::}{horizontalAdvance()} of the QChar::VisualTabCharacter character, otherwise the tab-character will be drawn incompletely.

See also
QTextOption::ShowTabsAndSpaces, QTextDocument::defaultTextOption

Definition at line 46 of file qtextedit.h.

◆ textInteractionFlags

Qt::TextInteractionFlags QTextEdit::textInteractionFlags
readwrite
Since
4.2

Specifies how the widget should interact with user input.

The default value depends on whether the QTextEdit is read-only or editable, and whether it is a QTextBrowser or not.

Definition at line 49 of file qtextedit.h.

◆ undoRedoEnabled

bool QTextEdit::undoRedoEnabled
readwrite

whether undo and redo are enabled.

Users are only able to undo or redo actions if this property is true, and if there is an action that can be undone (or redone).

Definition at line 33 of file qtextedit.h.


The documentation for this class was generated from the following files: