All the information about using QTextEdit as a display widget also
applies here.
QTextEdit provides command-based undo and redo. To set the depth
of the command history use setUndoDepth() which defaults to 100
steps. To undo or redo the last operation call undo() or redo().
The signals undoAvailable() and redoAvailable() indicate whether
the undo and redo operations can be executed.
The list of key-bindings which are implemented for editing:
Keypresses | Action
|
Backspace | Delete the character to the left of the cursor
|
Delete | Delete the character to the right of the cursor
|
Ctrl+A | Move the cursor to the beginning of the line
|
Ctrl+B | Move the cursor one character left
|
Ctrl+C | Copy the marked text to the clipboard (also
Ctrl+Insert under Windows)
|
Ctrl+D | Delete the character to the right of the cursor
|
Ctrl+E | Move the cursor to the end of the line
|
Ctrl+F | Move the cursor one character right
|
Ctrl+H | Delete the character to the left of the cursor
|
Ctrl+K | Delete to end of line
|
Ctrl+N | Move the cursor one line down
|
Ctrl+P | Move the cursor one line up
|
Ctrl+V | Paste the clipboard text into line edit
(also Shift+Insert under Windows)
|
Ctrl+X | Cut the marked text, copy to clipboard
(also Shift+Delete under Windows)
|
Ctrl+Z | Undo the last operation
|
Ctrl+Y | Redo the last operation
|
LeftArrow | Move the cursor one character left
|
Ctrl+LeftArrow | Move the cursor one word left
|
RightArrow | Move the cursor one character right
|
Ctrl+RightArrow | Move the cursor one word right
|
UpArrow | Move the cursor one line up
|
Ctrl+UpArrow | Move the cursor one word up
|
DownArrow | Move the cursor one line down
|
Ctrl+Down Arrow | Move the cursor one word down
|
PageUp | Move the cursor one page up
|
PageDown | Move the cursor one page down
|
Home | Move the cursor to the beginning of the line
|
Ctrl+Home | Move the cursor to the beginning of the text
|
End | Move the cursor to the end of the line
|
Ctrl+End | Move the cursor to the end of the text
|
Shift+Wheel | Scroll the page horizontally
(the Wheel is the mouse wheel)
|
Ctrl+Wheel | Zoom the text
|
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.
By default the text edit widget operates in insert mode so all
text that the user enters is inserted into the text edit and any
text to the right of the cursor is moved out of the way. The mode
can be changed to overwrite, where new text overwrites any text to
the right of the cursor, using setOverwriteMode().
See also Basic Widgets and Text Related Classes.
Member Type Documentation
QTextEdit::CursorAction
This enum is used by moveCursor() to specify in which direction
the cursor should be moved:
- QTextEdit::MoveBackward - Moves the cursor one character backward
- QTextEdit::MoveWordBackward - Moves the cursor one word backward
- QTextEdit::MoveForward - Moves the cursor one character forward
- QTextEdit::MoveWordForward - Moves the cursor one word forward
- QTextEdit::MoveUp - Moves the cursor up one line
- QTextEdit::MoveDown - Moves the cursor down one line
- QTextEdit::MoveLineStart - Moves the cursor to the beginning of the line
- QTextEdit::MoveLineEnd - Moves the cursor to the end of the line
- QTextEdit::MoveHome - Moves the cursor to the beginning of the document
- QTextEdit::MoveEnd - Moves the cursor to the end of the document
- QTextEdit::MovePgUp - Moves the cursor one viewport page up
- QTextEdit::MovePgDown - Moves the cursor one viewport page down
QTextEdit::KeyboardAction
This enum is used by doKeyboardAction() to specify which action
should be executed:
- QTextEdit::ActionBackspace - Delete the character to the left of the
cursor.
- QTextEdit::ActionDelete - Delete the character to the right of the
cursor.
- QTextEdit::ActionReturn - Split the paragraph at the cursor position.
- QTextEdit::ActionKill - If the cursor is not at the end of the
paragraph, delete the text from the cursor position until the end
of the paragraph. If the cursor is at the end of the paragraph,
delete the hard line break at the end of the paragraph: this will
cause this paragraph to be joined with the following paragraph.
QTextEdit::VerticalAlignment
This enum is used to set the vertical alignment of the text.
- QTextEdit::AlignNormal - Normal alignment
- QTextEdit::AlignSuperScript - Superscript
- QTextEdit::AlignSubScript - Subscript
QTextEdit::WordWrap
This enum defines the QTextEdit's word wrap modes.
- QTextEdit::NoWrap - Do not wrap the text.
- QTextEdit::WidgetWidth - Wrap the text at the current width of the
widget (this is the default). Wrapping is at whitespace by
default; this can be changed with setWrapPolicy().
- QTextEdit::FixedPixelWidth - Wrap the text at a fixed number of pixels
from the widget's left side. The number of pixels is set with
wrapColumnOrWidth().
- QTextEdit::FixedColumnWidth - Wrap the text at a fixed number of
character columns from the widget's left side. The number of
characters is set with wrapColumnOrWidth(). This is useful if you
need formatted text that can also be displayed gracefully on
devices with monospaced fonts, for example a standard VT100
terminal, where you might set wrapColumnOrWidth() to 80.
See also wordWrap and wordWrap.
QTextEdit::WrapPolicy
This enum defines where text can be wrapped in word wrap mode.
- QTextEdit::AtWhiteSpace - Break lines at whitespace, e.g. spaces or
newlines.
- QTextEdit::Anywhere - Break anywhere, including within words.
- QTextEdit::AtWordBoundary - Don't use this deprecated value (it is a
synonym for AtWhiteSpace which you should use instead).
See also wrapPolicy.
Member Function Documentation
QTextEdit::QTextEdit ( const QString & text, const QString & context = QString::null, QWidget * parent = 0, const char * name = 0 )
Constructs a QTextEdit called name, with parent parent. The
text edit will display the text text using context context.
The context is a path which the text edit's QMimeSourceFactory
uses to resolve the locations of files and images. It is passed to
the mimeSourceFactory() when quering data.
For example if the text contains an image tag,
<img src="image.png">, and the context is "path/to/look/in", the
QMimeSourceFactory will try to load the image from
"path/to/look/in/image.png". If the tag was
<img src="/image.png">, the context will not be used (because
QMimeSourceFactory recognizes that we have used an absolute path)
and will try to load "/image.png". The context is applied in exactly
the same way to hrefs, for example,
<a href="target.html">Target</a>, would resolve to
"path/to/look/in/target.html".
QTextEdit::QTextEdit ( QWidget * parent = 0, const char * name = 0 )
Constructs an empty QTextEdit called name, with parent parent.
int QTextEdit::alignment () const
Returns the alignment of the current paragraph.
See also setAlignment().
QString QTextEdit::anchorAt ( const QPoint & pos )
If there is an anchor at position pos (in contents
coordinates), its name is returned, otherwise an empty string is
returned.
void QTextEdit::append ( const QString & text ) [virtual slot]
Appends the text text to the end of the text edit. Note that
the undo/redo history is cleared by this function, and no undo
history is kept for appends which makes them faster than
insert()s.
Examples: network/clientserver/client/client.cpp, network/clientserver/server/server.cpp, network/httpd/httpd.cpp and process/process.cpp.
bool QTextEdit::bold () const
Returns TRUE if the current format is bold; otherwise returns FALSE.
See also setBold().
int QTextEdit::charAt ( const QPoint & pos, int * para ) const
Returns the index of the character (relative to its paragraph) at
position pos (in contents coordinates). If para is not 0, *para is set to this paragraph. If there is no character at pos,
-1 is returned and *para is undefined.
void QTextEdit::clear () [virtual slot]
Deletes all the text in the text edit.
See also cut(), removeSelectedText() and text.
void QTextEdit::clearParagraphBackground ( int para ) [virtual slot]
Clears the background color of the paragraph para, so that the
default color is used again.
QColor QTextEdit::color () const
Returns the color of the current format.
See also setColor() and paper.
QString QTextEdit::context () const
Returns the context of the text edit. The context is a path which
the text edit's QMimeSourceFactory uses to resolve the locations
of files and images.
See also text.
Examples: helpviewer/helpwindow.cpp and qdir/qdir.cpp.
void QTextEdit::copy () [virtual slot]
Copies any selected text (from selection 0) to the clipboard.
See also hasSelectedText and 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().
This function is called to create a right mouse button popup menu
at the document position pos. If you want to create a custom
popup menu, reimplement this function and return the created popup
menu. Ownership of the popup menu is transferred to the caller.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
This function is called to create a right mouse button popup menu.
If you want to create a custom popup menu, reimplement this function
and return the created popup menu. Ownership of the popup menu is
transferred to the caller.
This function is only called if createPopupMenu( const QPoint & )
returns 0.
void QTextEdit::currentAlignmentChanged ( int a ) [signal]
This signal is emitted if the alignment of the current paragraph
has changed.
The new alignment is a.
See also setAlignment().
void QTextEdit::currentColorChanged ( const QColor & c ) [signal]
This signal is emitted if the color of the current format has
changed.
The new color is c.
See also setColor().
void QTextEdit::currentFontChanged ( const QFont & f ) [signal]
This signal is emitted if the font of the current format has
changed.
The new font is f.
See also setCurrentFont().
void QTextEdit::currentVerticalAlignmentChanged ( VerticalAlignment a ) [signal]
This signal is emitted if the vertical alignment of the current
format has changed.
The new vertical alignment is a.
See also setVerticalAlignment().
void QTextEdit::cursorPositionChanged ( QTextCursor * c ) [signal]
This signal is emitted if the position of the cursor has changed.
c points to the text cursor object.
See also setCursorPosition().
void QTextEdit::cursorPositionChanged ( int para, int pos ) [signal]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
This signal is emitted if the position of the cursor has changed.
para contains the paragraph index and pos contains the
character position within the paragraph.
See also setCursorPosition().
void QTextEdit::cut () [virtual slot]
Copies the selected text (from selection 0) to the clipboard and
deletes it from the text edit.
If there is no selected text (in selection 0) nothing happens.
See also QTextEdit::copy(), paste() and pasteSubType().
void QTextEdit::del () [virtual slot]
If there is some selected text (in selection 0) it is deleted. If
there is no selected text (in selection 0) the character to the
right of the text cursor is deleted.
See also removeSelectedText() and cut().
void QTextEdit::doKeyboardAction ( KeyboardAction action ) [virtual slot]
Executes keyboard action action. This is normally called by a
key event handler.
QString QTextEdit::documentTitle () const
Returns the title of the document parsed from the text.
See the "documentTitle" property for details.
void QTextEdit::ensureCursorVisible () [virtual slot]
Ensures that the cursor is visible by scrolling the text edit if
necessary.
See also setCursorPosition().
QString QTextEdit::family () const
Returns the font family of the current format.
See also setFamily(), setCurrentFont() and setPointSize().
bool QTextEdit::find ( const QString & expr, bool cs, bool wo, bool forward = TRUE, int * para = 0, int * index = 0 ) [virtual]
Finds the next occurrence of the string, expr. Returns TRUE if
expr was found; otherwise returns FALSE.
If para and index are both 0 the search begins from the
current cursor position. If para and index are both not 0,
the search begins from the *index character position in the
*para paragraph.
If cs is TRUE the search is case sensitive, otherwise it is
case insensitive. If wo is TRUE the search looks for whole word
matches only; otherwise it searches for any matching text. If forward is TRUE (the default) the search works forward from the
starting position to the end of the text, otherwise it works
backwards to the beginning of the text.
If expr is found the function returns TRUE. If index and para are not 0, the number of the paragraph in which the first
character of the match was found is put into *para, and the
index position of that character within the paragraph is put into
*index.
If expr is not found the function returns FALSE. If index
and para are not 0 and expr is not found, *index
and *para are undefined.
bool QTextEdit::focusNextPrevChild ( bool n ) [virtual protected]
Reimplemented to allow tabbing through links. If n is TRUE the
tab moves the focus to the next child; if n is FALSE the tab
moves the focus to the previous child. Returns TRUE if the focus
was moved; otherwise returns FALSE.
QFont QTextEdit::font () const
Returns the font of the current format.
See also setCurrentFont(), setFamily() and setPointSize().
Examples: action/application.cpp, application/application.cpp, mdi/application.cpp and qwerty/qwerty.cpp.
void QTextEdit::getCursorPosition ( int * para, int * index ) const
This function sets the *para and *index parameters to the
current cursor position. para and index must not be 0.
See also setCursorPosition().
void QTextEdit::getSelection ( int * paraFrom, int * indexFrom, int * paraTo, int * indexTo, int selNum = 0 ) const
If there is a selection, *paraFrom is set to the number of the
paragraph in which the selection begins and *paraTo is set to
the number of the paragraph in which the selection ends. (They
could be the same.) *indexFrom is set to the index at which the
selection begins within *paraFrom, and *indexTo is set to
the index at which the selection ends within *paraTo.
If there is no selection, *paraFrom, *indexFrom, *paraTo
and *indexTo are all set to -1.
paraFrom, indexFrom, paraTo and indexTo must not be 0.
The selNum is the number of the selection (multiple selections
are supported). It defaults to 0 (the default selection).
See also setSelection() and selectedText.
bool QTextEdit::hasSelectedText () const
Returns TRUE if some text is selected in selection 0; otherwise returns FALSE.
See the "hasSelectedText" property for details.
int QTextEdit::heightForWidth ( int w ) const [virtual]
Returns how many pixels high the text edit needs to be to display
all the text if the text edit is w pixels wide.
Reimplemented from QWidget.
void QTextEdit::indent () [virtual slot]
Re-indents the current paragraph.
void QTextEdit::insert ( const QString & text, bool indent = FALSE, bool checkNewLine = TRUE, bool removeSelected = TRUE ) [virtual slot]
Inserts text at the current cursor position. If indent is
TRUE, the paragraph is re-indented. If checkNewLine is TRUE,
newline characters in text result in hard line breaks (i.e. new
paragraphs). If checkNewLine is FALSE and there are newlines in
text, the behavior is undefined. If checkNewLine is FALSE
the behaviour of the editor is undefined if the text contains
newlines. If removeSelected is TRUE, any selected text (in
selection 0) is removed before the text is inserted.
See also paste() and pasteSubType().
void QTextEdit::insertAt ( const QString & text, int para, int index ) [virtual slot]
Inserts text in the paragraph para at position index.
void QTextEdit::insertParagraph ( const QString & text, int para ) [virtual slot]
Inserts text as a new paragraph at position para. If para
is -1, the text is appended.
bool QTextEdit::isModified () const
Returns TRUE if the document has been modified by the user; otherwise returns FALSE.
See the "modified" property for details.
bool QTextEdit::isOverwriteMode () const
Returns the text edit's overwrite mode.
See the "overwriteMode" property for details.
bool QTextEdit::isReadOnly () const
Returns TRUE if the text edit is read-only; otherwise returns FALSE.
See the "readOnly" property for details.
bool QTextEdit::isRedoAvailable () const
Returns TRUE if redo is available; otherwise returns FALSE.
bool QTextEdit::isUndoAvailable () const
Returns TRUE if undo is available; otherwise returns FALSE.
bool QTextEdit::isUndoRedoEnabled () const
Returns TRUE if undo/redo is enabled; otherwise returns FALSE.
See the "undoRedoEnabled" property for details.
bool QTextEdit::italic () const
Returns TRUE if the current format is italic; otherwise returns FALSE.
See also setItalic().
void QTextEdit::keyPressEvent ( QKeyEvent * e ) [virtual protected]
Processes the key event, e. By default key events are used to
provide keyboard navigation and text editing.
Reimplemented from QWidget.
Reimplemented in QTextBrowser.
int QTextEdit::length () const
Returns the number of characters in the text.
See the "length" property for details.
int QTextEdit::lineOfChar ( int para, int index )
Returns the line number of the line in paragraph para in which
the character at position index appears. The index position is
relative to the beginning of the paragraph. If there is no such
paragraph or no such character at the index position (e.g. the
index is out of range) -1 is returned.
int QTextEdit::lines () const
Returns the number of lines in the text edit; this could be 0.
Warning: This function may be slow. Lines change all the time
during word wrapping, so this function has to iterate over all the
paragraphs and get the number of lines from each one individually.
Examples: action/application.cpp and application/application.cpp.
int QTextEdit::linesOfParagraph ( int para ) const
Returns the number of lines in paragraph para, or -1 if there
is no paragraph with index para.
bool QTextEdit::linkUnderline () const
Returns TRUE if hypertext links will be underlined; otherwise returns FALSE.
See the "linkUnderline" property for details.
QMimeSourceFactory * QTextEdit::mimeSourceFactory () const
Returns the QMimeSourceFactory which is being used by this text
edit.
See also setMimeSourceFactory().
Examples: helpviewer/helpwindow.cpp and qdir/qdir.cpp.
void QTextEdit::modificationChanged ( bool m ) [signal]
This signal is emitted when the modification status of the
document has changed. If m is TRUE, the document was modified,
otherwise the modification state has been reset to unmodified.
See also modified.
void QTextEdit::moveCursor ( CursorAction action, bool select ) [virtual slot]
Moves the text cursor according to action. This is normally
used by some key event handler. select specifies whether the
text between the current cursor position and the new position
should be selected.
QBrush QTextEdit::paper () const
Returns the background (paper) brush.
See the "paper" property for details.
int QTextEdit::paragraphAt ( const QPoint & pos ) const
Returns the paragraph which is at position pos (in contents
coordinates), or -1 if there is no paragraph with index pos.
QColor QTextEdit::paragraphBackgroundColor ( int para ) const
Returns the background color of the paragraph para or an
invalid color if para is out of range or the paragraph has no
background set
int QTextEdit::paragraphLength ( int para ) const
Returns the length of the paragraph para (i.e. the number of
characters), or -1 if there is no paragraph with index para
QRect QTextEdit::paragraphRect ( int para ) const
Returns the rectangle of the paragraph para in contents
coordinates, or an invalid rectangle if para is out of range.
int QTextEdit::paragraphs () const
Returns the number of paragraphs in the text; this could be 0.
void QTextEdit::paste () [virtual slot]
Pastes the text from the clipboard into the text edit at the
current cursor position. Only plain text is pasted.
If there is no text in the clipboard nothing happens.
See also pasteSubType(), cut() and QTextEdit::copy().
void QTextEdit::pasteSubType ( const QCString & subtype ) [virtual slot]
Pastes the text with format subtype from the clipboard into the
text edit at the current cursor position. The subtype can be
"plain" or "html".
If there is no text with format subtype in the clipboard
nothing happens.
See also paste(), cut() and QTextEdit::copy().
void QTextEdit::placeCursor ( const QPoint & pos, QTextCursor * c = 0 ) [virtual slot]
Places the cursor c at the character which is closest to
position pos (in contents coordinates). If c is 0, the
default text cursor is used.
See also setCursorPosition().
int QTextEdit::pointSize () const
Returns the point size of the font of the current format.
See also setFamily(), setCurrentFont() and setPointSize().
void QTextEdit::redo () [virtual slot]
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 redoAvailable(), undo() and undoDepth.
void QTextEdit::redoAvailable ( bool yes ) [signal]
This signal is emitted when the availability of redo changes. If
yes is TRUE, then redo() will work until redoAvailable( FALSE )
is next emitted.
See also redo() and undoDepth.
void QTextEdit::removeParagraph ( int para ) [virtual slot]
Removes the paragraph para.
void QTextEdit::removeSelectedText ( int selNum = 0 ) [virtual slot]
Deletes the text of selection selNum (by default, the default
selection, 0). If there is no selected text nothing happens.
See also selectedText and removeSelection().
void QTextEdit::removeSelection ( int selNum = 0 ) [virtual slot]
Removes the selection selNum (by default 0). This does not
remove the selected text.
See also removeSelectedText().
void QTextEdit::repaintChanged () [protected]
Repaints any paragraphs that have changed.
Although used extensively internally you shouldn't need to call
this yourself.
void QTextEdit::returnPressed () [signal]
This signal is emitted if the user pressed the Return or the Enter
key.
void QTextEdit::scrollToAnchor ( const QString & name ) [virtual slot]
Scrolls the text edit to make the text at the anchor called name visible, if it can be found in the document. If the anchor
isn't found no scrolling will occur. An anchor is defined using
the HTML anchor tag, e.g. <a name="target">.
void QTextEdit::scrollToBottom () [virtual slot]
Scrolls to the bottom of the document and does formatting if
required.
void QTextEdit::selectAll ( bool select = TRUE ) [virtual slot]
If select is TRUE (the default), all the text is selected as
selection 0. If select is FALSE any selected text is
unselected, i.e. the default selection (selection 0) is cleared.
See also selectedText.
QString QTextEdit::selectedText () const
Returns the selected text (from selection 0) or an empty string if there is no currently selected text (in selection 0).
See the "selectedText" property for details.
void QTextEdit::selectionChanged () [signal]
This signal is emitted whenever the selection changes.
See also setSelection() and copyAvailable().
void QTextEdit::setAlignment ( int a ) [virtual 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).
Reimplemented in QMultiLineEdit.
void QTextEdit::setBold ( bool b ) [virtual slot]
If b is TRUE sets the current format to bold; otherwise sets
the current format to non-bold.
See also bold().
void QTextEdit::setColor ( const QColor & c ) [virtual slot]
Sets the color of the current format, i.e. of the text, to c.
See also color() and paper.
void QTextEdit::setCurrentFont ( const QFont & f ) [virtual slot]
Sets the font of the current format to f.
See also font(), setPointSize() and setFamily().
void QTextEdit::setCursorPosition ( int para, int index ) [virtual slot]
Sets the cursor to position index in paragraph para.
See also getCursorPosition().
void QTextEdit::setFamily ( const QString & fontFamily ) [virtual slot]
Sets the font family of the current format to fontFamily.
See also family() and setCurrentFont().
void QTextEdit::setItalic ( bool b ) [virtual slot]
If b is TRUE sets the current format to italic; otherwise sets
the current format to non-italic.
See also italic().
void QTextEdit::setLinkUnderline ( bool ) [virtual slot]
Sets whether hypertext links will be underlined.
See the "linkUnderline" property for details.
void QTextEdit::setMimeSourceFactory ( QMimeSourceFactory * factory ) [virtual slot]
Sets the text edit's mimesource factory to factory. See
QMimeSourceFactory for further details.
See also mimeSourceFactory().
void QTextEdit::setModified ( bool m ) [virtual slot]
Sets whether the document has been modified by the user to m.
See the "modified" property for details.
void QTextEdit::setOverwriteMode ( bool b ) [virtual slot]
Sets the text edit's overwrite mode to b.
See the "overwriteMode" property for details.
void QTextEdit::setPaper ( const QBrush & pap ) [virtual slot]
Sets the background (paper) brush to pap.
See the "paper" property for details.
void QTextEdit::setParagraphBackgroundColor ( int para, const QColor & bg ) [virtual slot]
Sets the background color of the paragraph para to bg.
void QTextEdit::setPointSize ( int s ) [virtual slot]
Sets the point size of the current format to s.
Note that if s is zero or negative, the behaviour of this
function is not defined.
See also pointSize(), setCurrentFont() and setFamily().
void QTextEdit::setReadOnly ( bool b ) [virtual slot]
Sets whether the text edit is read-only to b.
See the "readOnly" property for details.
void QTextEdit::setSelection ( int paraFrom, int indexFrom, int paraTo, int indexTo, int selNum = 0 ) [virtual slot]
Sets a selection which starts at position indexFrom in
paragraph paraFrom and ends at position indexTo in paragraph
paraTo.
Any existing selections which have a different id (selNum) are
left alone, but if an existing selection has the same id as selNum it is removed and replaced by this selection.
Uses the selection settings of selection selNum. If selNum
is 0, this is the default selection.
The cursor is moved to the end of the selection if selNum is 0,
otherwise the cursor position remains unchanged.
See also getSelection() and selectedText.
void QTextEdit::setSelectionAttributes ( int selNum, const QColor & back, bool invertText ) [virtual slot]
Sets the background color of selection number selNum to back
and specifies whether the text of this selection should be
inverted with invertText.
This only works for selNum > 0. The default selection (selNum == 0) gets its attributes from the text edit's
colorGroup().
void QTextEdit::setStyleSheet ( QStyleSheet * styleSheet ) [virtual slot]
Sets the stylesheet to use with this text edit to styleSheet.
Changes will only take effect for new text added with setText() or
append().
See also styleSheet().
void QTextEdit::setTabStopWidth ( int ts ) [virtual slot]
Sets the tab stop width in pixels to ts.
See the "tabStopWidth" property for details.
void QTextEdit::setText ( const QString & txt ) [slot]
Sets the text edit's text to txt.
See the "text" property for details.
void QTextEdit::setText ( const QString & text, const QString & context ) [virtual slot]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Changes the text of the text edit to the string text and the
context to context. Any previous text is removed.
text may be interpreted either as plain text or as rich text,
depending on the textFormat(). The default setting is AutoText,
i.e. the text edit auto-detects the format from text.
The optional context is a path which the text edit's
QMimeSourceFactory uses to resolve the locations of files and
images. (See QTextEdit::QTextEdit().) It is passed to the text
edit's QMimeSourceFactory when quering data.
Note that the undo/redo history is cleared by this function.
See also text and textFormat.
void QTextEdit::setTextFormat ( TextFormat f ) [virtual slot]
Sets the text format: rich text, plain text or auto text to f.
See the "textFormat" property for details.
void QTextEdit::setUnderline ( bool b ) [virtual slot]
If b is TRUE sets the current format to underline; otherwise
sets the current format to non-underline.
See also underline().
void QTextEdit::setUndoDepth ( int d ) [virtual slot]
Sets the depth of the undo history to d.
See the "undoDepth" property for details.
void QTextEdit::setUndoRedoEnabled ( bool b ) [virtual slot]
Sets whether undo/redo is enabled to b.
See the "undoRedoEnabled" property for details.
void QTextEdit::setVerticalAlignment ( VerticalAlignment a ) [virtual slot]
Sets the vertical alignment of the current format, i.e. of the
text, to a.
See also color() and paper.
void QTextEdit::setWordWrap ( WordWrap mode ) [virtual slot]
Sets the word wrap mode to mode.
See the "wordWrap" property for details.
void QTextEdit::setWrapColumnOrWidth ( int ) [virtual slot]
Sets the position (in pixels or columns depending on the wrap mode) where text will be wrapped.
See the "wrapColumnOrWidth" property for details.
void QTextEdit::setWrapPolicy ( WrapPolicy policy ) [virtual slot]
Sets the word wrap policy, at whitespace or anywhere to policy.
See the "wrapPolicy" property for details.
QStyleSheet * QTextEdit::styleSheet () const
Returns the QStyleSheet which is being used by this text edit.
See also setStyleSheet().
Example: helpviewer/helpwindow.cpp.
int QTextEdit::tabStopWidth () const
Returns the tab stop width in pixels.
See the "tabStopWidth" property for details.
QString QTextEdit::text () const
Returns the text edit's text.
See the "text" property for details.
QString QTextEdit::text ( int para ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns the text of paragraph para.
If textFormat() is RichText the text will contain HTML
formatting tags.
void QTextEdit::textChanged () [signal]
This signal is emitted whenever the text in the text edit changes.
See also text and append().
Examples: helpviewer/helpwindow.cpp, qwerty/qwerty.cpp and rot13/rot13.cpp.
QTextCursor * QTextEdit::textCursor () const [protected]
Returns the text edit's text cursor.
Warning: QTextCursor is not in the public API, but in special
circumstances you might wish to use it.
TextFormat QTextEdit::textFormat () const
Returns the text format: rich text, plain text or auto text.
See the "textFormat" property for details.
bool QTextEdit::underline () const
Returns TRUE if the current format is underlined; otherwise returns
FALSE.
See also setUnderline().
void QTextEdit::undo () [virtual slot]
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 undoAvailable(), redo() and undoDepth.
void QTextEdit::undoAvailable ( bool yes ) [signal]
This signal is emitted when the availability of undo changes. If
yes is TRUE, then undo() will work until undoAvailable( FALSE )
is next emitted.
See also undo() and undoDepth.
int QTextEdit::undoDepth () const
Returns the depth of the undo history.
See the "undoDepth" property for details.
WordWrap QTextEdit::wordWrap () const
Returns the word wrap mode.
See the "wordWrap" property for details.
int QTextEdit::wrapColumnOrWidth () const
Returns the position (in pixels or columns depending on the wrap mode) where text will be wrapped.
See the "wrapColumnOrWidth" property for details.
WrapPolicy QTextEdit::wrapPolicy () const
Returns the word wrap policy, at whitespace or anywhere.
See the "wrapPolicy" property for details.
void QTextEdit::zoomIn ( int range ) [virtual slot]
Zooms in on the text by by making the base font size range
points larger and recalculating all font sizes. This does not
change the size of any images.
See also zoomOut().
void QTextEdit::zoomIn () [virtual slot]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Zooms in on the text by by making the base font size one point
larger and recalculating all font sizes. This does not change the
size of any images.
See also zoomOut().
void QTextEdit::zoomOut ( int range ) [virtual slot]
Zooms out on the text by making the base font size range points
smaller and recalculating all font sizes. This does not change the
size of any images.
See also zoomIn().
void QTextEdit::zoomOut () [virtual slot]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Zooms out on the text by by making the base font size one point
smaller and recalculating all font sizes. This does not change the
size of any images.
See also zoomIn().
void QTextEdit::zoomTo ( int size ) [virtual slot]
Zooms the text by making the base font size size points and
recalculating all font sizes. This does not change the size of any
images.
Property Documentation
This property holds the title of the document parsed from the text.
For PlainText the title will be an empty string. For RichText the title will be the text between the <title> tags,
if present, otherwise an empty string.
Get this property's value with documentTitle().
bool hasSelectedText
This property holds whether some text is selected in selection 0.
Get this property's value with hasSelectedText().
int length
This property holds the number of characters in the text.
Get this property's value with length().
bool linkUnderline
This property holds whether hypertext links will be underlined.
If TRUE (the default) hypertext links will be displayed
underlined. If FALSE links will not be displayed underlined.
Set this property's value with setLinkUnderline() and get this property's value with linkUnderline().
bool modified
This property holds whether the document has been modified by the user.
Set this property's value with setModified() and get this property's value with isModified().
bool overwriteMode
This property holds the text edit's overwrite mode.
If FALSE (the default) characters entered by the user are inserted
with any characters to the right being moved out of the way. If
TRUE, the editor is in overwrite mode, i.e. characters entered by
the user overwrite any characters to the right of the cursor
position.
Set this property's value with setOverwriteMode() and get this property's value with isOverwriteMode().
This property holds the background (paper) brush.
The brush that is currently used to draw the background of the
text edit. The initial setting is an empty brush.
Set this property's value with setPaper() and get this property's value with paper().
bool readOnly
This property holds 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.
Set this property's value with setReadOnly() and get this property's value with isReadOnly().
This property holds the selected text (from selection 0) or an empty string if there is no currently selected text (in selection 0).
The text is always returned as PlainText regardless of the text
format. In a future version of Qt an HTML subset may be
returned depending on the text format.
See also hasSelectedText.
Get this property's value with selectedText().
int tabStopWidth
This property holds the tab stop width in pixels.
Set this property's value with setTabStopWidth() and get this property's value with tabStopWidth().
This property holds the text edit's text.
There is no default text.
On setting, any previous text is deleted.
The text may be interpreted either as plain text or as rich text,
depending on the textFormat(). The default setting is AutoText,
i.e. the text edit auto-detects the format of the text.
For richtext, calling text() on an editable QTextEdit will cause
the text to be regenerated from the textedit. This may mean that
the QString returned may not be exactly the same as the one that
was set.
See also textFormat.
Set this property's value with setText() and get this property's value with text().
This property holds the text format: rich text, plain text or auto text.
The text format is one of the following:
- PlainText - all characters, except newlines, are displayed
verbatim, including spaces. Whenever a newline appears in the text the
text edit inserts a hard line break and begins a new paragraph.
- RichText - rich text rendering. The available styles are
defined in the default stylesheet QStyleSheet::defaultSheet().
- AutoText - this is the default. The text edit autodetects
which rendering style is best, PlainText or RichText. This is
done by using the QStyleSheet::mightBeRichText() function.
Set this property's value with setTextFormat() and get this property's value with textFormat().
int undoDepth
This property holds the depth of the undo history.
The maximum number of steps in the undo/redo history. The default
is 100.
See also undo() and redo().
Set this property's value with setUndoDepth() and get this property's value with undoDepth().
bool undoRedoEnabled
This property holds whether undo/redo is enabled.
The default is TRUE.
Set this property's value with setUndoRedoEnabled() and get this property's value with isUndoRedoEnabled().
This property holds the word 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 setWrapPolicy(). If you set a wrap mode of
FixedPixelWidth or FixedColumnWidth you should also call
setWrapColumnOrWidth() with the width you want.
See also WordWrap, wrapColumnOrWidth and wrapPolicy.
Set this property's value with setWordWrap() and get this property's value with wordWrap().
int wrapColumnOrWidth
This property holds 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.
See also wordWrap.
Set this property's value with setWrapColumnOrWidth() and get this property's value with wrapColumnOrWidth().
This property holds the word wrap policy, at whitespace or anywhere.
Defines where text can be wrapped when word wrap mode is not NoWrap. The choices are AtWhiteSpace (the default) and Anywhere.
See also wordWrap.
Set this property's value with setWrapPolicy() and get this property's value with wrapPolicy().
This file is part of the Qt toolkit.
Copyright © 1995-2002
Trolltech. All Rights Reserved.