Q3TextEdit Class

The Q3TextEdit widget provides a powerful single-page rich text editor. 更多...

头: #include <Q3TextEdit>
继承: Q3ScrollView
继承者: Q3MultiLineEdit , Q3TextBrowser ,和 Q3TextView

公共类型

flags AutoFormatting
enum AutoFormattingFlag { AutoNone, AutoBulletList, AutoAll }
enum CursorAction { MoveBackward, MoveWordBackward, MoveForward, MoveWordForward, ..., MovePgDown }
enum KeyboardAction { ActionBackspace, ActionDelete, ActionReturn, ActionKill, ActionWordBackspace, ActionWordDelete }
enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript }
enum WordWrap { NoWrap, WidgetWidth, FixedPixelWidth, FixedColumnWidth }
enum WrapPolicy { AtWhiteSpace, Anywhere, AtWordBoundary, AtWordOrDocumentBoundary }

特性

公共函数

Q3TextEdit (const QString & text , const QString & context = QString(), QWidget * parent = 0, const char * name = 0)
Q3TextEdit (QWidget * parent = 0, const char * name = 0)
virtual ~Q3TextEdit ()
int alignment () const
QString anchorAt (const QPoint & pos , Qt::AnchorAttribute attr = Qt::AnchorHref)
AutoFormatting autoFormatting () const
bool bold () const
int charAt (const QPoint & pos , int * para ) const
QColor color () const
QString context () const
QFont currentFont () const
QString documentTitle () const
QString family () const
virtual bool find (const QString & expr , bool cs , bool wo , bool forward = true, int * para = 0, int * index = 0)
QFont font () const
void getCursorPosition (int * para , int * index ) const
void getSelection (int * paraFrom , int * indexFrom , int * paraTo , int * indexTo , int selNum = 0) const
bool hasSelectedText () const
bool isModified () const
bool isOverwriteMode () const
bool isReadOnly () const
bool isRedoAvailable () const
bool isUndoAvailable () const
bool isUndoRedoEnabled () const
bool italic () const
int length () const
int lineOfChar (int para , int index )
int lines () const
int linesOfParagraph (int para ) const
bool linkUnderline () const
Q3MimeSourceFactory * mimeSourceFactory () const
QBrush paper () const
int paragraphAt (const QPoint & pos ) const
QColor paragraphBackgroundColor (int para ) const
int paragraphLength (int para ) const
QRect paragraphRect (int para ) const
int paragraphs () const
int pointSize () const
QString selectedText () const
void setAutoFormatting (AutoFormatting)
Q3StyleSheet * styleSheet () const
Q3SyntaxHighlighter * syntaxHighlighter () const
bool tabChangesFocus () const
int tabStopWidth () const
QString text () const
QString text (int para ) const
Qt::TextFormat textFormat () const
bool underline () const
int undoDepth () const
VerticalAlignment verticalAlignment () const
WordWrap wordWrap () const
int wrapColumnOrWidth () const
WrapPolicy wrapPolicy () const

重实现公共函数

virtual bool eventFilter (QObject * o , QEvent * e )
virtual int heightForWidth (int w ) const
virtual QSize sizeHint () const

公共槽

virtual void append (const QString & text )
virtual void clear ()
virtual void clearParagraphBackground (int para )
virtual void copy ()
virtual void cut ()
virtual void del ()
virtual void doKeyboardAction (Q3TextEdit::KeyboardAction action )
virtual void ensureCursorVisible ()
virtual void insert (const QString & text , uint insertionFlags = CheckNewLines | RemoveSelected)
virtual void insert (const QString & text , bool indent , bool checkNewLine = true, bool removeSelected = true)
virtual void insertAt (const QString & text , int para , int index )
virtual void insertParagraph (const QString & text , int para )
virtual void moveCursor (Q3TextEdit::CursorAction action , bool select )
virtual void paste ()
virtual void pasteSubType (const QByteArray & subtype )
virtual void placeCursor (const QPoint & pos , Q3TextCursor * c = 0)
virtual void redo ()
virtual void removeParagraph (int para )
virtual void removeSelectedText (int selNum = 0)
virtual void removeSelection (int selNum = 0)
virtual void scrollToAnchor (const QString & name )
virtual void scrollToBottom ()
virtual void selectAll (bool select = true)
virtual void setAlignment (int a )
virtual void setBold (bool b )
virtual void setColor (const QColor & c )
virtual void setCurrentFont (const QFont & f )
virtual void setCursorPosition (int para , int index )
virtual void setFamily (const QString & fontFamily )
virtual void setItalic (bool b )
virtual void setLinkUnderline (bool)
virtual void setMimeSourceFactory (Q3MimeSourceFactory * factory )
virtual void setModified (bool m )
virtual void setOverwriteMode (bool b )
virtual void setPaper (const QBrush & pap )
virtual void setParagraphBackgroundColor (int para , const QColor & bg )
virtual void setPointSize (int s )
virtual void setReadOnly (bool b )
virtual void setSelection (int paraFrom , int indexFrom , int paraTo , int indexTo , int selNum = 0)
virtual void setSelectionAttributes (int selNum , const QColor & back , bool invertText )
virtual void setStyleSheet (Q3StyleSheet * styleSheet )
virtual void setTabChangesFocus (bool b )
virtual void setTabStopWidth (int ts )
void setText (const QString & txt )
virtual void setText (const QString & text , const QString & context )
virtual void setTextFormat (Qt::TextFormat f )
virtual void setUnderline (bool b )
virtual void setUndoDepth (int d )
virtual void setUndoRedoEnabled (bool b )
virtual void setVerticalAlignment (Q3TextEdit::VerticalAlignment a )
virtual void setWordWrap (Q3TextEdit::WordWrap mode )
virtual void setWrapColumnOrWidth (int)
virtual void setWrapPolicy (Q3TextEdit::WrapPolicy policy )
virtual void sync ()
virtual void undo ()
virtual void zoomIn (int range )
virtual void zoomIn ()
virtual void zoomOut (int range )
virtual void zoomOut ()
virtual void zoomTo (int size )

信号

void clicked (int para , int pos )
void copyAvailable (bool yes )
void currentAlignmentChanged (int a )
void currentColorChanged (const QColor & c )
void currentFontChanged (const QFont & f )
void currentVerticalAlignmentChanged (Q3TextEdit::VerticalAlignment a )
void cursorPositionChanged (int para , int pos )
void doubleClicked (int para , int pos )
void modificationChanged (bool m )
void redoAvailable (bool yes )
void returnPressed ()
void selectionChanged ()
void textChanged ()
void undoAvailable (bool yes )

保护函数

virtual Q3PopupMenu * createPopupMenu (const QPoint & pos )
virtual Q3PopupMenu * createPopupMenu ()
void repaintChanged ()
Q3TextCursor * textCursor () const

重实现保护函数

virtual void changeEvent (QEvent * ev )
virtual void contentsContextMenuEvent (QContextMenuEvent * e )
virtual void contentsDragEnterEvent (QDragEnterEvent * e )
virtual void contentsDragLeaveEvent (QDragLeaveEvent * e )
virtual void contentsDragMoveEvent (QDragMoveEvent * e )
virtual void contentsDropEvent (QDropEvent * e )
virtual void contentsMouseDoubleClickEvent (QMouseEvent * e )
virtual void contentsMouseMoveEvent (QMouseEvent * e )
virtual void contentsMousePressEvent (QMouseEvent * e )
virtual void contentsMouseReleaseEvent (QMouseEvent * e )
virtual void contentsWheelEvent (QWheelEvent * e )
virtual void drawContents (QPainter * p , int cx , int cy , int cw , int ch )
virtual bool event (QEvent * e )
virtual bool focusNextPrevChild (bool n )
virtual void inputMethodEvent (QInputMethodEvent * e )
virtual void keyPressEvent (QKeyEvent * e )
virtual void resizeEvent (QResizeEvent * e )
virtual void viewportResizeEvent (QResizeEvent * e )

额外继承成员

详细描述

The Q3TextEdit widget provides a powerful single-page rich text editor.

介绍和概念

Q3TextEdit 是支持使用 HTML 样式标签格式富文本的高级 WYSIWYG (所见即所得) 查看器/编辑器。经优化,能处理大文档和快速响应用户输入。

Q3TextEdit has four modes of operation:

模式 Command 注意事项
Plain Text Editor setTextFormat ( Qt::PlainText ) Set text with setText (); text () returns plain text. Text attributes (e.g. colors) can be set, but plain text is always returned.
Rich Text Editor setTextFormat ( Qt::RichText ) Set text with setText (); text () returns rich text. Rich text editing is fairly limited. You can't set margins or insert images for example (although you can read and correctly display files that have margins set and that include images). This mode is mostly useful for editing small amounts of rich text.
Text Viewer setReadOnly (true) Set text with setText () 或 append () (which has no undo history so is faster and uses less memory); text () returns plain or rich text depending on the textFormat (). This mode can correctly display a large subset of HTML tags.
Log Viewer setTextFormat ( Qt::LogText ) Append text using append (). The widget is set to be read only and rich text support is disabled although a few HTML tags (for color, bold, italic and underline) may be used. (See Qt::LogText mode 了解细节。)

Q3TextEdit can be used as a syntax highlighting editor when used in conjunction with QSyntaxHighlighter .

We recommend that you always call setTextFormat () to set the mode you want to use. If you use Qt::AutoText then setText () 和 append () will try to determine whether the text they are given is plain text or rich text. If you use Qt::RichText then setText () 和 append () will assume that the text they are given is rich text. insert () simply inserts the text it is given.

Q3TextEdit works on paragraphs and characters. A paragraph is a formatted string which is word-wrapped to fit into the width of the widget. By default when reading plain text, one newline signify a paragraph. A document consists of zero or more paragraphs, indexed from 0. Characters are indexed on a per-paragraph basis, also indexed from 0. The words in the paragraph are aligned in accordance with the paragraph's alignment (). Paragraphs are separated by hard line breaks. Each character within a paragraph has its own attributes, for example, font and color.

The text edit documentation uses the following concepts:

  • current format -- this is the format at the current cursor position, and it is the format of the selected text if any.
  • current paragraph -- the paragraph which contains the cursor.

Q3TextEdit can display images (using Q3MimeSourceFactory ), lists and tables. If the text is too large to view within the text edit's viewport, scroll bars will appear. The text edit can load both plain text and HTML files (a subset of HTML 3.2 and 4). The rendering style and the set of valid tags are defined by a styleSheet (). Custom tags can be created and placed in a custom style sheet. Change the style sheet with setStyleSheet (); see Q3StyleSheet for details. The images identified by image tags are displayed if they can be interpreted using the text edit's Q3MimeSourceFactory ;见 setMimeSourceFactory ().

If you want a text browser with more navigation use QTextBrowser . If you just need to display a small piece of rich text use QLabel or QSimpleRichText .

If you create a new Q3TextEdit , and want to allow the user to edit rich text, call setTextFormat ( Qt::RichText ) to ensure that the text is treated as rich text. (Rich text uses HTML tags to set text formatting attributes. See Q3StyleSheet for information on the HTML tags that are supported.). If you don't call setTextFormat () explicitly the text edit will guess from the text itself whether it is rich text or plain text. This means that if the text looks like HTML or XML it will probably be interpreted as rich text, so you should call setTextFormat ( Qt::PlainText ) to preserve such text.

Note that we do not intend to add a full-featured web browser widget to Qt (because that would easily double Qt's size and only a few applications would benefit from it). The rich text support in Qt is designed to provide a fast, portable and efficient way to add reasonable online help facilities to applications, and to provide a basis for rich text editors.

Using Q3TextEdit as a Display Widget

Q3TextEdit 可以显示大 HTML 子集,包括表格和图像。

设置或替代文本使用 setText () 删除并替换任何现有文本,采用将文本传入 setText () 调用。若调用 setText () with legacy HTML (with setTextFormat ( Qt::RichText ) in force), and then call text (), the text that is returned may have different markup, but will render the same. Text can be inserted with insert (), paste (), pasteSubType () 和 append (). Text that is appended does not go into the undo history; this makes append () faster and consumes less memory. Text can also be cut (). The entire text is deleted with clear () and the selected text is deleted with removeSelectedText (). Selected (marked) text can also be deleted with del () (which will delete the character to the right of the cursor if no text is selected).

Loading and saving text is achieved using setText () 和 text (), for example:

QFile file(fileName); // Read the text from a file
if (file.open(IO_ReadOnly)) {
    QTextStream stream(&file);
    textEdit->setText(stream.read());
}
QFile file(fileName); // Write the text to a file
if (file.open(IO_WriteOnly)) {
    QTextStream stream(&file);
    stream << textEdit->text();
    textEdit->setModified(false);
}
					

默认情况下,文本编辑在空白处自动换行以拟合在文本编辑 Widget 中。 setWordWrap () function is used to specify the kind of word wrap you want, or NoWrap 若不想要任何换行。调用 setWordWrap () 去设置固定像素宽度 FixedPixelWidth ,或字符列 (如:80 列) FixedColumnWidth 按指定像素或列数采用 setWrapColumnOrWidth ()。若使用自动换行到 Widget 的宽度 WidgetWidth ,可以指定是在空白处断开还是在任何地方断开采用 setWrapPolicy ().

The background color is set differently than other widgets, using setPaper (). You specify a brush style which could be a plain color or a complex pixmap.

Hypertext links are automatically underlined; this can be changed with setLinkUnderline (). The tab stop width is set with setTabStopWidth ().

The zoomIn () 和 zoomOut () functions can be used to resize the text by increasing (decreasing for zoomOut ()) the point size used. Images are not affected by the zoom functions.

The lines () function returns the number of lines in the text and paragraphs () returns the number of paragraphs. The number of lines within a particular paragraph is returned by linesOfParagraph (). The length of the entire text in characters is returned by length ().

You can scroll to an anchor in the text, e.g. <a name="anchor"> with scrollToAnchor ()。 find () 函数可以用于在文本中查找和选择给定字符串。

A read-only Q3TextEdit provides the same functionality as the (obsolete) QTextView . ( QTextView is still supplied for compatibility with old code.)

Read-only key bindings

Q3TextEdit is used read-only the key-bindings are limited to navigation, and text may only be selected with the mouse:

按键 动作
Up Move one line up
Down Move one line down
Left Move one character left
Right Move one character right
PageUp Move one (viewport) page up
PageDown Move one (viewport) page down
Home Move to the beginning of the text
End Move to the end of the text
Shift+Wheel Scroll the page horizontally (the Wheel is the mouse wheel)
Ctrl+Wheel Zoom the text

文本编辑可能能够提供一些元信息。例如, documentTitle () 函数将返回文本从 HTML <title> 标签。

The text displayed in a text edit has a context . The context is a path which the text edit's Q3MimeSourceFactory uses to resolve the locations of files and images. It is passed to the mimeSourceFactory () when quering data. (See Q3TextEdit () 和 context ().)

Using Q3TextEdit in Qt::LogText Mode

Setting the text format to Qt::LogText puts the widget in a special mode which is optimized for very large texts. In this mode editing and rich text support are disabled (the widget is explicitly set to read-only mode). This allows the text to be stored in a different, more memory efficient manner. However, a certain degree of text formatting is supported through the use of formatting tags. A tag is delimited by < and > . The characters < , > and & are escaped by using < , > and & . A tag pair consists of a left and a right tag (or open/close tags). Left-tags mark the starting point for formatting, while right-tags mark the ending point. A right-tag always start with a / before the tag keyword. For example <b> and </b> are a tag pair. Tags can be nested, but they have to be closed in the same order as they are opened. For example, <b><u></u></b> is valid, while <b><u></b></u> will output an error message.

By using tags it is possible to change the color, bold, italic and underline settings for a piece of text. A color can be specified by using the HTML font tag <font color=colorname> . The color name can be one of the color names from the X11 color database, or a RGB hex value (e.g #00ff00 ). Example of valid color tags: <font color=red> , <font color="light blue"> , <font color="#223344"> . Bold, italic and underline settings can be specified by the tags <b> , <i> and <u> . Note that a tag does not necessarily have to be closed. A valid example:

This is <font color=red>red</font> while <b>this</b> is <font color=blue>blue</font>.
<font color=green><font color=yellow>Yellow,</font> and <u>green</u>.
					

Stylesheets can also be used in Qt::LogText mode. To create and use a custom tag, you could do the following:

Q3TextEdit * log = new Q3TextEdit(this);
log->setTextFormat(Qt::LogText);
Q3StyleSheetItem * item = new Q3StyleSheetItem(log->styleSheet(), "mytag");
item->setColor("red");
item->setFontWeight(QFont::Bold);
item->setFontUnderline(true);
log->append("This is a <mytag>custom tag</mytag>!");
					

Note that only the color, bold, underline and italic attributes of a Q3StyleSheetItem 用于 Qt::LogText 模式。

Note that you can use setMaxLogLines() to limit the number of lines the widget can hold in Qt::LogText 模式。

There are a few things that you need to be aware of when the widget is in this mode:

  • Functions that deal with rich text formatting and cursor movement will not work or return anything valid.
  • Lines are equivalent to paragraphs.

Using Q3TextEdit as an Editor

所有信息有关使用 Q3TextEdit 作为显示 Widget 在此也适用。

The current format's attributes are set with setItalic (), setBold (), setUnderline (), setFamily () (font family), setPointSize (), setColor () 和 setCurrentFont ()。设置当前段落的对齐方式采用 setAlignment ().

使用 setSelection () to select text. The setSelectionAttributes () function is used to indicate how selected text should be displayed. Use hasSelectedText () to find out if any text is selected. The currently selected text's position is available using getSelection () and the selected text itself is returned by selectedText ()。选定可以被拷贝到剪贴板采用 copy (),或剪切到剪贴板采用 cut (). It can be deleted with removeSelectedText (). The entire text can be selected (or unselected) using selectAll (). Q3TextEdit supports multiple selections. Most of the selection functions operate on the default selection, selection 0. If the user presses a non-selecting key, e.g. a cursor key without also holding down Shift, all selections are cleared.

Set and get the position of the cursor with setCursorPosition () 和 getCursorPosition () respectively. When the cursor is moved, the signals currentFontChanged (), currentColorChanged () 和 currentAlignmentChanged () are emitted to reflect the font, color and alignment at the new cursor position.

If the text changes, the textChanged () signal is emitted, and if the user inserts a new line by pressing Return or Enter, returnPressed () is emitted. The isModified () function will return true if the text has been modified.

Q3TextEdit 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 () 或 redo (). The signals undoAvailable () 和 redoAvailable () indicate whether the undo and redo operations can be executed.

Editing key bindings

The list of key-bindings which are implemented for editing:

按键 动作
Backspace Delete the character to the left of the cursor
删除 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
Left Move the cursor one character left
Ctrl+Left Move the cursor one word left
Right Move the cursor one character right
Ctrl+Right Move the cursor one word right
Up Move the cursor one line up
Ctrl+Qt::Up Move the cursor one word up
DownArrow Move the cursor one line down
Ctrl+Down 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

要选择 (标记) 文本,在按住 Shift 键的同时按下某一移动击键,例如, Shift+Right 将选择右侧字符,而 Shift+Ctrl+Right 将选择右侧单词,等等。

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 ().

成员类型文档编制

enum Q3TextEdit:: AutoFormattingFlag
flags Q3TextEdit:: AutoFormatting

常量 描述
Q3TextEdit::AutoNone 0 Do not perform any automatic formatting
Q3TextEdit::AutoBulletList 0x00000001 Only automatically format bulletted lists
Q3TextEdit::AutoAll 0xffffffff Apply all available autoformatting

AutoFormatting 类型是 typedef 对于 QFlags <AutoFormattingFlag>。它存储 AutoFormattingFlag 值的 OR 组合。

enum Q3TextEdit:: CursorAction

此枚举用于 moveCursor () to specify in which direction the cursor should be moved:

常量 描述
Q3TextEdit::MoveBackward 0 Moves the cursor one character backward
Q3TextEdit::MoveWordBackward 2 Moves the cursor one word backward
Q3TextEdit::MoveForward 1 Moves the cursor one character forward
Q3TextEdit::MoveWordForward 3 Moves the cursor one word forward
Q3TextEdit::MoveUp 4 Moves the cursor up one line
Q3TextEdit::MoveDown 5 Moves the cursor down one line
Q3TextEdit::MoveLineStart 6 Moves the cursor to the beginning of the line
Q3TextEdit::MoveLineEnd 7 Moves the cursor to the end of the line
Q3TextEdit::MoveHome 8 Moves the cursor to the beginning of the document
Q3TextEdit::MoveEnd 9 Moves the cursor to the end of the document
Q3TextEdit::MovePgUp 10 Moves the cursor one viewport page up
Q3TextEdit::MovePgDown 11 Moves the cursor one viewport page down

enum Q3TextEdit:: KeyboardAction

此枚举用于 doKeyboardAction () to specify which action should be executed:

常量 描述
Q3TextEdit::ActionBackspace 0 Delete the character to the left of the cursor.
Q3TextEdit::ActionDelete 1 Delete the character to the right of the cursor.
Q3TextEdit::ActionReturn 2 Split the paragraph at the cursor position.
Q3TextEdit::ActionKill 3 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.
Q3TextEdit::ActionWordBackspace 4 Delete the word to the left of the cursor position.
Q3TextEdit::ActionWordDelete 5 Delete the word to the right of the cursor position

enum Q3TextEdit:: VerticalAlignment

This enum is used to set the vertical alignment of the text.

常量 描述
Q3TextEdit::AlignNormal 0 Normal alignment
Q3TextEdit::AlignSuperScript 1 Superscript
Q3TextEdit::AlignSubScript 2 Subscript

enum Q3TextEdit:: WordWrap

This enum defines the Q3TextEdit 's word wrap modes.

常量 描述
Q3TextEdit::NoWrap 0 Do not wrap the text.
Q3TextEdit::WidgetWidth 1 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 ().
Q3TextEdit::FixedPixelWidth 2 Wrap the text at a fixed number of pixels from the widget's left side. The number of pixels is set with wrapColumnOrWidth ().
Q3TextEdit::FixedColumnWidth 3 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.

另请参阅 setWordWrap () 和 wordWrap ().

enum Q3TextEdit:: WrapPolicy

This enum defines where text can be wrapped in word wrap mode.

常量 描述
Q3TextEdit::AtWhiteSpace AtWordBoundary Don't use this deprecated value (it is a synonym for AtWordBoundary which you should use instead).
Q3TextEdit::Anywhere ? Break anywhere, including within words.
Q3TextEdit::AtWordBoundary 0 Break lines at word boundaries, e.g. spaces or newlines
Q3TextEdit::AtWordOrDocumentBoundary ? Break lines at whitespace, e.g. spaces or newlines if possible. Break it anywhere otherwise.

另请参阅 setWrapPolicy ().

特性文档编制

autoFormatting : AutoFormattingFlag

This property holds the enabled set of auto formatting features.

值可以是值的任何组合在 AutoFormattingFlag 枚举。默认为 AutoAll 。选取 AutoNone to disable all automatic formatting.

目前,唯一提供的自动格式化特征是 AutoBulletList ;未来版本的 Qt 可能提供更多。

访问函数:

AutoFormatting autoFormatting () const
void setAutoFormatting (AutoFormatting)

documentTitle : const QString

此特性保持剖析自文本的文档标题。

For Qt::PlainText the title will be an empty string. For Qt::RichText the title will be the text between the <title> tags, if present, otherwise an empty string.

访问函数:

QString documentTitle () const

hasSelectedText : const bool

This property holds whether some text is selected in selection 0.

访问函数:

bool hasSelectedText () const

length : const int

This property holds the number of characters in the text.

访问函数:

int length () const

linkUnderline : bool

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.

访问函数:

bool linkUnderline () const
virtual void setLinkUnderline (bool)

modified : bool

This property holds whether the document has been modified by the user.

访问函数:

bool isModified () const
virtual void setModified (bool m )

overwriteMode : bool

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.

访问函数:

bool isOverwriteMode () const
virtual void setOverwriteMode (bool b )

paper : QBrush

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.

访问函数:

QBrush paper () const
virtual void setPaper (const QBrush & pap )

readOnly : bool

This property holds whether the text edit is read-only.

在只读文本编辑中,用户只能导航文本和选择文本;修改文本是不可能的。

此特性默认为 false。

访问函数:

bool isReadOnly () const
virtual void setReadOnly (bool b )

selectedText : const QString

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 Qt::PlainText textFormat () 是 Qt::PlainText or Qt::AutoText , otherwise it is returned as HTML.

访问函数:

QString selectedText () const

另请参阅 hasSelectedText .

tabChangesFocus : bool

This property holds whether 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 TAB key, as this breaks the focus chain. The default is false.

访问函数:

bool tabChangesFocus () const
virtual void setTabChangesFocus (bool b )

tabStopWidth : int

此特性保持 Tab (制表符) 停止宽度 (以像素为单位)。

访问函数:

int tabStopWidth () const
virtual void setTabStopWidth (int ts )

text : QString

This property holds the text edit's 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 ()。默认设置为 Qt::AutoText , i.e. the text edit auto-detects the format of the text.

For richtext, calling text() on an editable Q3TextEdit 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.

访问函数:

QString text () const
QString text (int para ) const
void setText (const QString & txt )
virtual void setText (const QString & text , const QString & context )

另请参阅 textFormat .

textFormat : Qt::TextFormat

This property holds the text format: rich text, plain text, log text or auto text.

The text format is one of the following:

访问函数:

Qt::TextFormat textFormat () const
virtual void setTextFormat (Qt::TextFormat f )

undoDepth : int

This property holds the depth of the undo history.

The maximum number of steps in the undo/redo history. The default is 100.

访问函数:

int undoDepth () const
virtual void setUndoDepth (int d )

另请参阅 undo () 和 redo ().

undoRedoEnabled : bool

This property holds whether undo/redo is enabled.

When changing this property, the undo/redo history is cleared.

默认为 true。

访问函数:

bool isUndoRedoEnabled () const
virtual void setUndoRedoEnabled (bool b )

wordWrap : WordWrap

This property holds the word wrap mode.

默认模式为 WidgetWidth 导致单词在文本编辑右边缘换行。换行出现在空白处,保持整个单词完整。若想要换行发生在单词内,使用 setWrapPolicy ()。若将换行模式设为 FixedPixelWidth or FixedColumnWidth 还应调用 setWrapColumnOrWidth () 采用想要的宽度。

访问函数:

WordWrap wordWrap () const
virtual void setWordWrap (Q3TextEdit::WordWrap mode )

另请参阅 WordWrap , wrapColumnOrWidth ,和 wrapPolicy .

wrapColumnOrWidth : int

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

若换行模式为 FixedPixelWidth ,值是从文本编辑左边缘开始 (文本应在哪里换行) 的像素数。若换行模式为 FixedColumnWidth ,值是从文本编辑左边缘开始 (文本应在哪里换行) 的列号 (以字符列为单位)。

访问函数:

int wrapColumnOrWidth () const
virtual void setWrapColumnOrWidth (int)

另请参阅 wordWrap .

wrapPolicy : WrapPolicy

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 AtWordBoundary (默认), Anywhere and AtWordOrDocumentBoundary

访问函数:

WrapPolicy wrapPolicy () const
virtual void setWrapPolicy (Q3TextEdit::WrapPolicy policy )

另请参阅 wordWrap .

成员函数文档编制

Q3TextEdit:: Q3TextEdit (const QString & text , const QString & context = QString(), QWidget * parent = 0, const char * name = 0)

构造 Q3TextEdit called name ,采用父级 parent 。文本编辑将显示文本 text using context context .

The context is a path which the text edit's Q3MimeSourceFactory 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 Q3MimeSourceFactory 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 Q3MimeSourceFactory 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".

Q3TextEdit:: Q3TextEdit ( QWidget * parent = 0, const char * name = 0)

构造空的 Q3TextEdit called name ,采用父级 parent .

[虚拟] Q3TextEdit:: ~Q3TextEdit ()

析构函数。

int Q3TextEdit:: alignment () const

返回当前段落的对齐方式。

另请参阅 setAlignment ().

QString Q3TextEdit:: anchorAt (const QPoint & pos , Qt::AnchorAttribute attr = Qt::AnchorHref)

Returns the text for the attribute attr ( Qt::AnchorHref by default) if there is an anchor at position pos (in contents coordinates); otherwise returns an empty string.

[virtual slot] void Q3TextEdit:: append (const QString & 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. If you want to append text which is added to the undo/redo history as well, use insertParagraph ().

bool Q3TextEdit:: bold () const

Returns true if the current format is bold; otherwise returns false.

另请参阅 setBold ().

[virtual protected] void Q3TextEdit:: changeEvent ( QEvent * ev )

重实现自 QWidget::changeEvent ().

int Q3TextEdit:: 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 the character's paragraph.

[virtual slot] void Q3TextEdit:: clear ()

删除文本编辑中的所有文本。

另请参阅 cut (), removeSelectedText (),和 setText ().

[virtual slot] void Q3TextEdit:: clearParagraphBackground ( int para )

Clears the background color of the paragraph para , so that the default color is used again.

[signal] void Q3TextEdit:: clicked ( int para , int pos )

This signal is emitted when the mouse is clicked on the paragraph para at character position pos .

另请参阅 doubleClicked ().

QColor Q3TextEdit:: color () const

Returns the color of the current format.

另请参阅 setColor () 和 setPaper ().

[virtual protected] void Q3TextEdit:: contentsContextMenuEvent ( QContextMenuEvent * e )

重实现自 Q3ScrollView::contentsContextMenuEvent ().

[virtual protected] void Q3TextEdit:: contentsDragEnterEvent ( QDragEnterEvent * e )

重实现自 Q3ScrollView::contentsDragEnterEvent ().

[virtual protected] void Q3TextEdit:: contentsDragLeaveEvent ( QDragLeaveEvent * e )

重实现自 Q3ScrollView::contentsDragLeaveEvent ().

[virtual protected] void Q3TextEdit:: contentsDragMoveEvent ( QDragMoveEvent * e )

重实现自 Q3ScrollView::contentsDragMoveEvent ().

[virtual protected] void Q3TextEdit:: contentsDropEvent ( QDropEvent * e )

重实现自 Q3ScrollView::contentsDropEvent ().

[virtual protected] void Q3TextEdit:: contentsMouseDoubleClickEvent ( QMouseEvent * e )

重实现自 Q3ScrollView::contentsMouseDoubleClickEvent ().

[virtual protected] void Q3TextEdit:: contentsMouseMoveEvent ( QMouseEvent * e )

重实现自 Q3ScrollView::contentsMouseMoveEvent ().

[virtual protected] void Q3TextEdit:: contentsMousePressEvent ( QMouseEvent * e )

重实现自 Q3ScrollView::contentsMousePressEvent ().

[virtual protected] void Q3TextEdit:: contentsMouseReleaseEvent ( QMouseEvent * e )

重实现自 Q3ScrollView::contentsMouseReleaseEvent ().

[virtual protected] void Q3TextEdit:: contentsWheelEvent ( QWheelEvent * e )

重实现自 Q3ScrollView::contentsWheelEvent ().

QString Q3TextEdit:: context () const

Returns the context of the text edit. The context is a path which the text edit's Q3MimeSourceFactory uses to resolve the locations of files and images.

另请参阅 text .

[virtual slot] void Q3TextEdit:: copy ()

Copies any selected text (from selection 0) to the clipboard.

另请参阅 hasSelectedText () 和 copyAvailable ().

[signal] void Q3TextEdit:: copyAvailable ( bool yes )

此信号被发射当在文本编辑中选择或取消选择文本时。

当有文本被选中时,此信号会被发射采用 yes 设为 true。若没有文本被选中或选中文本被取消选择,此信号被发射采用 yes 设为 false。

yes 为 True 则 copy () 可以用于把选定拷贝到剪贴板。若 yes 为 false 则 copy () 什么都不做。

另请参阅 selectionChanged ().

[virtual protected] Q3PopupMenu * Q3TextEdit:: createPopupMenu (const QPoint & pos )

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.

警告: The QPopupMenu ID values 0-7 are reserved, and they map to the standard operations. When inserting items into your custom popup menu, be sure to specify ID values larger than 7.

[virtual protected] Q3PopupMenu * Q3TextEdit:: createPopupMenu ()

这是重载函数。

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.

[signal] void Q3TextEdit:: currentAlignmentChanged ( int a )

This signal is emitted if the alignment of the current paragraph has changed.

The new alignment is a .

另请参阅 setAlignment ().

[signal] void Q3TextEdit:: currentColorChanged (const QColor & c )

This signal is emitted if the color of the current format has changed.

The new color is c .

另请参阅 setColor ().

QFont Q3TextEdit:: currentFont () const

返回当前格式的字体。

另请参阅 setCurrentFont (), setFamily (),和 setPointSize ().

[signal] void Q3TextEdit:: currentFontChanged (const QFont & f )

This signal is emitted if the font of the current format has changed.

The new font is f .

另请参阅 setCurrentFont ().

[signal] void Q3TextEdit:: currentVerticalAlignmentChanged ( Q3TextEdit::VerticalAlignment a )

This signal is emitted if the vertical alignment of the current format has changed.

The new vertical alignment is a .

[signal] void Q3TextEdit:: cursorPositionChanged ( int para , int pos )

这是重载函数。

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.

注意: 信号 cursorPositionChanged 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:

connect(3TextEdit, static_cast<void(Q3TextEdit::*)(int, int)>(&Q3TextEdit::cursorPositionChanged),
    [=](int para, int pos){ /* ... */ });
					

另请参阅 setCursorPosition ().

[virtual slot] void Q3TextEdit:: cut ()

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.

另请参阅 Q3TextEdit::copy (), paste (),和 pasteSubType ().

[virtual slot] void Q3TextEdit:: del ()

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.

另请参阅 removeSelectedText () 和 cut ().

[virtual slot] void Q3TextEdit:: doKeyboardAction ( Q3TextEdit::KeyboardAction action )

Executes keyboard action action . This is normally called by a key event handler.

[signal] void Q3TextEdit:: doubleClicked ( int para , int pos )

This signal is emitted when the mouse is double-clicked on the paragraph para at character position pos .

另请参阅 clicked ().

[virtual protected] void Q3TextEdit:: drawContents ( QPainter * p , int cx , int cy , int cw , int ch )

重实现自 Q3ScrollView::drawContents ().

[virtual slot] void Q3TextEdit:: ensureCursorVisible ()

通过卷动文本编辑确保光标是可见的,若有必要。

另请参阅 setCursorPosition ().

[virtual protected] bool Q3TextEdit:: event ( QEvent * e )

重实现自 QObject::event ().

[虚拟] bool Q3TextEdit:: eventFilter ( QObject * o , QEvent * e )

重实现自 QObject::eventFilter ().

QString Q3TextEdit:: family () const

返回当前格式的字体系列。

另请参阅 setFamily (), setCurrentFont (),和 setPointSize ().

[虚拟] bool Q3TextEdit:: find (const QString & expr , bool cs , bool wo , bool forward = true, int * para = 0, int * index = 0)

查找下一出现为字符串 expr . Returns true if expr was found; otherwise returns false.

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.

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.

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 .

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.

Please note that this function will make the next occurrence of the string (if found) the current selection, and will thus modify the cursor position.

使用 para and index parameters will not work correctly in case the document contains tables.

[virtual protected] bool Q3TextEdit:: focusNextPrevChild ( bool n )

重实现自 QWidget::focusNextPrevChild ().

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 Q3TextEdit:: font () const

返回 Q3ScrollView::font ()

警告: In previous versions this function returned the font of the current format. This lead to confusion. Please use currentFont () 代替。

void Q3TextEdit:: getCursorPosition ( int * para , int * index ) const

此函数设置 * para and * index parameters to the current cursor position. para and index must not be 0.

另请参阅 setCursorPosition ().

void Q3TextEdit:: 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 ,和 * 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 or indexTo is 0 this function does nothing.

The selNum is the number of the selection (multiple selections are supported). It defaults to 0 (the default selection).

另请参阅 setSelection () 和 selectedText .

[虚拟] int Q3TextEdit:: heightForWidth ( int w ) const

重实现自 QWidget::heightForWidth ().

Returns how many pixels high the text edit needs to be to display all the text if the text edit is w pixels wide.

[virtual protected] void Q3TextEdit:: inputMethodEvent ( QInputMethodEvent * e )

重实现自 QWidget::inputMethodEvent ().

[virtual slot] void Q3TextEdit:: insert (const QString & text , uint insertionFlags = CheckNewLines | RemoveSelected)

插入 text 在当前光标位置。

The insertionFlags define how the text is inserted. If RedoIndentation is set, the paragraph is re-indented. If CheckNewLines is set, newline characters in text result in hard line breaks (i.e. new paragraphs). If checkNewLine is not set, the behavior of the editor is undefined if the text contains newlines. (It is not possible to change Q3TextEdit 's newline handling behavior, but you can use QString::replace () to preprocess text before inserting it.) If RemoveSelected is set, any selected text (in selection 0) is removed before the text is inserted.

The default flags are CheckNewLines | RemoveSelected .

If the widget is in Qt::LogText mode this function will do nothing.

另请参阅 paste () 和 pasteSubType ().

[virtual slot] void Q3TextEdit:: insert (const QString & text , bool indent , bool checkNewLine = true, bool removeSelected = true)

插入给定 text 。若 indent is true the paragraph that contains the text is reindented; if checkNewLine 为 true text is checked for newlines and relaid out. If removeSelected is true and there is a selection, the insertion replaces the selected text.

[virtual slot] void Q3TextEdit:: insertAt (const QString & text , int para , int index )

插入 text in the paragraph para 在位置 index .

[virtual slot] void Q3TextEdit:: insertParagraph (const QString & text , int para )

插入 text as a new paragraph at position para 。若 para is -1, the text is appended. Use append () if the append operation is performance critical.

bool Q3TextEdit:: isRedoAvailable () const

Returns true if redo is available; otherwise returns false.

bool Q3TextEdit:: isUndoAvailable () const

Returns true if undo is available; otherwise returns false.

bool Q3TextEdit:: italic () const

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

另请参阅 setItalic ().

[virtual protected] void Q3TextEdit:: keyPressEvent ( QKeyEvent * e )

重实现自 QWidget::keyPressEvent ().

Processes the key event, e . By default key events are used to provide keyboard navigation and text editing.

int Q3TextEdit:: 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 Q3TextEdit:: lines () const

Returns the number of lines in the text edit; this could be 0.

警告: 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.

int Q3TextEdit:: linesOfParagraph ( int para ) const

Returns the number of lines in paragraph para , or -1 if there is no paragraph with index para .

Q3MimeSourceFactory * Q3TextEdit:: mimeSourceFactory () const

返回 Q3MimeSourceFactory which is being used by this text edit.

另请参阅 setMimeSourceFactory ().

[signal] void Q3TextEdit:: modificationChanged ( bool m )

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.

另请参阅 modified .

[virtual slot] void Q3TextEdit:: moveCursor ( Q3TextEdit::CursorAction action , bool select )

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.

int Q3TextEdit:: paragraphAt (const QPoint & pos ) const

Returns the paragraph which is at position pos (in contents coordinates).

QColor Q3TextEdit:: 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

另请参阅 setParagraphBackgroundColor ().

int Q3TextEdit:: 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 .

This function ignores newlines.

QRect Q3TextEdit:: paragraphRect ( int para ) const

Returns the rectangle of the paragraph para in contents coordinates, or an invalid rectangle if para 超出范围。

int Q3TextEdit:: paragraphs () const

Returns the number of paragraphs in the text; an empty textedit is always considered to have one paragraph, so 1 is returned in this case.

[virtual slot] void Q3TextEdit:: paste ()

Pastes the text from the clipboard into the text edit at the current cursor position. Only plain text is pasted.

若剪贴板中没有文本,什么都不发生。

另请参阅 pasteSubType (), cut (),和 Q3TextEdit::copy ().

[virtual slot] void Q3TextEdit:: pasteSubType (const QByteArray & subtype )

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.

另请参阅 paste (), cut (),和 Q3TextEdit::copy ().

[virtual slot] void Q3TextEdit:: placeCursor (const QPoint & pos , Q3TextCursor * c = 0)

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.

另请参阅 setCursorPosition ().

int Q3TextEdit:: pointSize () const

返回当前格式的字体点大小。

另请参阅 setFamily (), setCurrentFont (),和 setPointSize ().

[virtual slot] void Q3TextEdit:: redo ()

重做上一操作。

若没有要重做的操 (即:在撤消/重做历史中没有重做步骤),则什么都不发生。

另请参阅 redoAvailable (), undo (),和 undoDepth ().

[signal] void Q3TextEdit:: redoAvailable ( bool yes )

This signal is emitted when the availability of redo changes. If yes 为 true,则 redo () will work until redoAvailable(false) is next emitted.

另请参阅 redo () 和 undoDepth ().

[virtual slot] void Q3TextEdit:: removeParagraph ( int para )

Removes the paragraph para .

[virtual slot] void Q3TextEdit:: removeSelectedText ( int selNum = 0)

Deletes the text of selection selNum (by default, the default selection, 0). If there is no selected text nothing happens.

另请参阅 selectedText and removeSelection ().

[virtual slot] void Q3TextEdit:: removeSelection ( int selNum = 0)

Removes the selection selNum (by default 0). This does not remove the selected text.

另请参阅 removeSelectedText ().

[protected] void Q3TextEdit:: repaintChanged ()

Repaints any paragraphs that have changed.

Although used extensively internally you shouldn't need to call this yourself.

[virtual protected] void Q3TextEdit:: resizeEvent ( QResizeEvent * e )

重实现自 QWidget::resizeEvent ().

[signal] void Q3TextEdit:: returnPressed ()

This signal is emitted if the user pressed the Return or the Enter key.

[virtual slot] void Q3TextEdit:: scrollToAnchor (const QString & name )

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"> .

[virtual slot] void Q3TextEdit:: scrollToBottom ()

Scrolls to the bottom of the document and does formatting if required.

[virtual slot] void Q3TextEdit:: selectAll ( bool select = true)

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.

另请参阅 selectedText .

[signal] void Q3TextEdit:: selectionChanged ()

此信号被发射每当选定改变时。

另请参阅 setSelection () 和 copyAvailable ().

[virtual slot] void Q3TextEdit:: setAlignment ( int a )

把当前段落的对齐方式设为 a 。有效对齐方式是 Qt::AlignLeft , Qt::AlignRight , Qt::AlignJustify and Qt::AlignCenter (水平居中)。

另请参阅 alignment ().

[virtual slot] void Q3TextEdit:: setBold ( bool b )

b is true sets the current format to bold; otherwise sets the current format to non-bold.

另请参阅 bold ().

[virtual slot] void Q3TextEdit:: setColor (const QColor & c )

Sets the color of the current format, i.e. of the text, to c .

另请参阅 color () 和 setPaper ().

[virtual slot] void Q3TextEdit:: setCurrentFont (const QFont & f )

把当前格式的字体设为 f .

If the widget is in Qt::LogText mode this function will do nothing. Use setFont () 代替。

另请参阅 currentFont (), setPointSize (),和 setFamily ().

[virtual slot] void Q3TextEdit:: setCursorPosition ( int para , int index )

Sets the cursor to position index in paragraph para .

另请参阅 getCursorPosition ().

[virtual slot] void Q3TextEdit:: setFamily (const QString & fontFamily )

把当前格式的字体系列设为 fontFamily .

另请参阅 family () 和 setCurrentFont ().

[virtual slot] void Q3TextEdit:: setItalic ( bool b )

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

另请参阅 italic ().

[virtual slot] void Q3TextEdit:: setMimeSourceFactory ( Q3MimeSourceFactory * factory )

Sets the text edit's mimesource factory to factory 。见 Q3MimeSourceFactory 进一步了解细节。

另请参阅 mimeSourceFactory ().

[virtual slot] void Q3TextEdit:: setParagraphBackgroundColor ( int para , const QColor & bg )

Sets the background color of the paragraph para to bg .

另请参阅 paragraphBackgroundColor ().

[virtual slot] void Q3TextEdit:: setPointSize ( int s )

将当前格式的点大小设为 s .

注意,若 s 为 0 (或负值),此函数的行为未定义。

另请参阅 pointSize (), setCurrentFont (),和 setFamily ().

[virtual slot] void Q3TextEdit:: setSelection ( int paraFrom , int indexFrom , int paraTo , int indexTo , int selNum = 0)

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 。若 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.

另请参阅 getSelection () 和 selectedText .

[virtual slot] void Q3TextEdit:: setSelectionAttributes ( int selNum , const QColor & back , bool invertText )

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 palette ().

[virtual slot] void Q3TextEdit:: setStyleSheet ( Q3StyleSheet * styleSheet )

Sets the stylesheet to use with this text edit to styleSheet . Changes will only take effect for new text added with setText () 或 append ().

另请参阅 styleSheet ().

[virtual slot] void Q3TextEdit:: setUnderline ( bool b )

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

另请参阅 underline ().

[virtual slot] void Q3TextEdit:: setVerticalAlignment ( Q3TextEdit::VerticalAlignment a )

Sets the vertical alignment of the current format, i.e. of the text, to a .

另请参阅 verticalAlignment (), color (),和 setPaper ().

[虚拟] QSize Q3TextEdit:: sizeHint () const

重实现自 QWidget::sizeHint ().

Q3StyleSheet * Q3TextEdit:: styleSheet () const

返回 Q3StyleSheet which is being used by this text edit.

另请参阅 setStyleSheet ().

[virtual slot] void Q3TextEdit:: sync ()

Q3TextEdit is optimized for large amounts text. One of its optimizations is to format only the visible text, formatting the rest on demand, e.g. as the user scrolls, so you don't usually need to call this function.

In some situations you may want to force the whole text to be formatted. For example, if after calling setText (), you wanted to know the height of the document (using contentsHeight ()), you would call this function first.

Q3SyntaxHighlighter * Q3TextEdit:: syntaxHighlighter () const

返回 QSyntaxHighlighter set on this Q3TextEdit . 0 is returned if no syntax highlighter is set.

[signal] void Q3TextEdit:: textChanged ()

This signal is emitted whenever the text in the text edit changes.

另请参阅 setText () 和 append ().

[protected] Q3TextCursor * Q3TextEdit:: textCursor () const

Returns the text edit's text cursor.

警告: Q3TextCursor is not in the public API, but in special circumstances you might wish to use it.

bool Q3TextEdit:: underline () const

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

另请参阅 setUnderline ().

[virtual slot] void Q3TextEdit:: undo ()

撤消上一操作。

若没有要撤消的操作 (即:撤消/重做历史中没有撤消步骤),什么都不发生。

另请参阅 undoAvailable (), redo (),和 undoDepth ().

[signal] void Q3TextEdit:: undoAvailable ( bool yes )

This signal is emitted when the availability of undo changes. If yes 为 true,则 undo () will work until undoAvailable(false) is next emitted.

另请参阅 undo () 和 undoDepth ().

VerticalAlignment Q3TextEdit:: verticalAlignment () const

Returns the vertical alignment of the current format.

另请参阅 setVerticalAlignment ().

[virtual protected] void Q3TextEdit:: viewportResizeEvent ( QResizeEvent * e )

重实现自 Q3ScrollView::viewportResizeEvent ().

[virtual slot] void Q3TextEdit:: zoomIn ( int range )

放大文本通过使基字体大小 range 点变得更大并将所有字体大小重新计算成新大小。这不会改变任何图像大小。

另请参阅 zoomOut ().

[virtual slot] void Q3TextEdit:: zoomIn ()

这是重载函数。

Zooms in on the text by making the base font size one point larger and recalculating all font sizes to be the new size. This does not change the size of any images.

另请参阅 zoomOut ().

[virtual slot] void Q3TextEdit:: zoomOut ( int range )

缩小文本通过使基字体大小 range 点变得更小并将所有字体大小重新计算成新大小。这不会改变任何图像大小。

另请参阅 zoomIn ().

[virtual slot] void Q3TextEdit:: zoomOut ()

这是重载函数。

Zooms out on the text by making the base font size one point smaller and recalculating all font sizes to be the new size. This does not change the size of any images.

另请参阅 zoomIn ().

[virtual slot] void Q3TextEdit:: zoomTo ( int size )

Zooms the text by making the base font size size points and recalculating all font sizes to be the new size. This does not change the size of any images.