📄 qtextedit.3qt
字号:
textEdit->setModified( FALSE );.br }.br.fi.PPBy default the text edit wraps words at whitespace to fit within the text edit widget. The setWordWrap() function is used to specify the kind of word wrap you want, or NoWrap if you don't want any wrapping. Call setWordWrap() to set a fixed pixel width FixedPixelWidth, or character column (e.g. 80 column) FixedColumnWidth with the pixels or columns specified with setWrapColumnOrWidth(). If you use word wrap to the widget's width WidgetWidth, you can specify whether to break on whitespace or anywhere with setWrapPolicy()..PPThe 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..PPHypertext links are automatically underlined; this can be changed with setLinkUnderline(). The tab stop width is set with setTabStopWidth()..PPThe zoomIn() and 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..PPThe 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()..PPYou can scroll to an anchor in the text, e.g. \fC<a name="anchor">\fR with scrollToAnchor(). The find() function can be used to find and select a given string within the text..PPThe list of key-bindings which are implemented for editing:.TP\fI Backspace \fR -- Delete the character to the left of the cursor.TP\fI Delete \fR -- Delete the character to the right of the cursor.TP\fI Ctrl+A \fR -- Move the cursor to the beginning of the line.TP\fI Ctrl+B \fR -- Move the cursor one character left.TP\fI Ctrl+C \fR -- Copy the marked text to the clipboard (also \fICtrl+Insert\fR under Windows).TP\fI Ctrl+D \fR -- Delete the character to the right of the cursor.TP\fI Ctrl+E \fR -- Move the cursor to the end of the line.TP\fI Ctrl+F \fR -- Move the cursor one character right.TP\fI Ctrl+H \fR -- Delete the character to the left of the cursor.TP\fI Ctrl+K \fR -- Delete to end of line.TP\fI Ctrl+N \fR -- Move the cursor one line down.TP\fI Ctrl+P \fR -- Move the cursor one line up.TP\fI Ctrl+V \fR -- Paste the clipboard text into line edit (also \fIShift+Insert\fR under Windows).TP\fI Ctrl+X \fR -- Cut the marked text, copy to clipboard (also \fIShift+Delete\fR under Windows).TP\fI Ctrl+Z \fR -- Undo the last operation.TP\fI Ctrl+Y \fR -- Redo the last operation.TP\fI Left Arrow \fR -- Move the cursor one character left.TP\fI Ctrl+Left Arrow \fR -- Move the cursor one word left.TP\fI Right Arrow \fR -- Move the cursor one character right.TP\fI Ctrl+Right Arrow \fR -- Move the cursor one word right.TP\fI Up Arrow \fR -- Move the cursor one line up.TP\fI Ctrl+Up Arrow \fR -- Move the cursor one word up.TP\fI Down Arrow \fR -- Move the cursor one line down.TP\fI Ctrl+Down Arrow \fR -- Move the cursor one word down.TP\fI Page Up \fR -- Move the cursor one page up.TP\fI Page Down \fR -- Move the cursor one page down.TP\fI Home \fR -- Move the cursor to the beginning of the line.TP\fI Ctrl+Home Arrow \fR -- Move the cursor to the beginning of the text.TP\fI End \fR -- Move the cursor to the end of the line.TP\fI Ctrl+End Arrow \fR -- Move the cursor to the end of the text.TP\fI Shift+Wheel\fR -- Scroll the page horizontally (the Wheel is the mouse wheel).TP\fI Ctrl+Wheel\fR -- Zoom the text.PPTo select (mark) text hold down the Shift key whilst pressing one of the movement keystrokes, for example, \fIShift+Right Arrow\fR will select the character to the right, and \fIShift+Ctrl+Right Arrow\fR will select the word to the right, etc..PPBy 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()..PPQTextEdit can also be used as read-only text viewer. Call setReadOnly( TRUE ) to disable editing. A read-only QTextEdit provides the same functionality as the (obsolete) QTextView. (QTextView is still supplied for compatibility with old code.).PPWhen QTextEdit is used read-only the key-bindings are limited to navigation, and text may only be selected with the mouse:.TP\fI Up Arrow \fR -- Move one line up.TP\fI Down Arrow \fR -- Move one line down.TP\fI Left Arrow \fR -- Move one character left.TP\fI Right Arrow \fR -- Move one character right.TP\fI Page Up \fR -- Move one (viewport) page up.TP\fI Page Down \fR -- Move one (viewport) page down.TP\fI Home \fR -- Move to the beginning of the text.TP\fI End \fR -- Move to the end of the text.TP\fI Shift+Wheel\fR -- Scroll the page horizontally (the Wheel is the mouse wheel).TP\fI Ctrl+Wheel\fR -- Zoom the text.PPThe text edit may be able to provide some meta-information. For example, the documentTitle() function will return the text from within HTML \fC<title>\fR tags..PPThe text displayed in a text edit has a \fIcontext\fR. 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. (See QTextEdit() and context().).PPNote 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..PPSee also Basic Widgets and Text Related Classes..SS "Member Type Documentation".SH "QTextEdit::CursorAction"This enum is used by moveCursor() to specify in which direction the cursor should be moved:.TP\fCQTextEdit::MoveBackward\fR - Moves the cursor one character backward.TP\fCQTextEdit::MoveWordBackward\fR - Moves the cursor one word backward.TP\fCQTextEdit::MoveForward\fR - Moves the cursor one character forward.TP\fCQTextEdit::MoveWordForward\fR - Moves the cursor one word forward.TP\fCQTextEdit::MoveUp\fR - Moves the cursor up one line.TP\fCQTextEdit::MoveDown\fR - Moves the cursor down one line.TP\fCQTextEdit::MoveLineStart\fR - Moves the cursor to the beginning of the line.TP\fCQTextEdit::MoveLineEnd\fR - Moves the cursor to the end of the line.TP\fCQTextEdit::MoveHome\fR - Moves the cursor to the beginning of the document.TP\fCQTextEdit::MoveEnd\fR - Moves the cursor to the end of the document.TP\fCQTextEdit::MovePgUp\fR - Moves the cursor one page up.TP\fCQTextEdit::MovePgDown\fR - Moves the cursor one page down.SH "QTextEdit::KeyboardAction"This enum is used by doKeyboardAction() to specify which action should be executed:.TP\fCQTextEdit::ActionBackspace\fR - Delete the character to the left of the cursor..TP\fCQTextEdit::ActionDelete\fR - Delete the character to the right of the cursor..TP\fCQTextEdit::ActionReturn\fR - Split the paragraph at the cursor position..TP\fCQTextEdit::ActionKill\fR - 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..SH "QTextEdit::VerticalAlignment"This enum is used to set the vertical alignment of the text..TP\fCQTextEdit::AlignNormal\fR - Normal alignment.TP\fCQTextEdit::AlignSuperScript\fR - Superscript.TP\fCQTextEdit::AlignSubScript\fR - Subscript.SH "QTextEdit::WordWrap"This enum defines the QTextEdit's word wrap modes. The following values are valid:.TP\fCQTextEdit::NoWrap\fR - Do not wrap the text..TP\fCQTextEdit::WidgetWidth\fR - 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()..TP\fCQTextEdit::FixedPixelWidth\fR - Wrap the text at a fixed number of pixels from the widget's left side. The number of pixels is set with wrapColumnOrWidth()..TP\fCQTextEdit::FixedColumnWidth\fR - 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..PPSee also wordWrap and wordWrap..SH "QTextEdit::WrapPolicy"This enum defines where text can be wrapped in word wrap mode..PPThe following values are valid:.TP\fCQTextEdit::AtWhiteSpace\fR - Break lines at whitespace, e.g. spaces or newlines..TP\fCQTextEdit::Anywhere\fR - Break anywhere, including within words..TP\fCQTextEdit::AtWordBoundary\fR - Don't use this deprecated value (it is a synonym for AtWhiteSpace which you should use instead)..PPSee also wrapPolicy..SH MEMBER FUNCTION DOCUMENTATION.SH "QTextEdit::QTextEdit ( const QString & text, const QString & context = QString::null, QWidget * parent = 0, const char * name = 0 )"Constructs a QTextEdit with parent \fIparent\fR and name \fIname\fR. The text edit will display the text \fItext\fR using context \fIcontext\fR..PPThe \fIcontext\fR 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..PPFor example if the text contains an image tag, \fC<img src="image.png">\fR, 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 \fC<img src="/image.png">\fR, 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 \fIhrefs\fR, for example, \fC<a href="target.html">Target</a>\fR, would resolve to" path/to/look/in/target.html"..SH "QTextEdit::QTextEdit ( QWidget * parent = 0, const char * name = 0 )"Constructs an empty QTextEdit with parent \fIparent\fR and name \fIname\fR..SH "int QTextEdit::alignment () const"Returns the alignment of the current paragraph..PPSee also setAlignment()..SH "QString QTextEdit::anchorAt ( const QPoint & pos )"If there is an anchor at position \fIpos\fR (in contents coordinates), its name is returned, otherwise an empty string is returned..SH "void QTextEdit::append ( const QString & text )\fC [virtual slot]\fR"Appends the text \fItext\fR to the end of the text edit..PPExamples:.)l network/clientserver/client/client.cpp, network/clientserver/server/server.cpp, network/httpd/httpd.cpp and process/process.cpp..SH "bool QTextEdit::bold () const"Returns TRUE if the current format is bold; otherwise returns FALSE..PPSee also setBold()..SH "int QTextEdit::charAt ( const QPoint & pos, int * para ) const"Returns the index of the character (relative to its paragraph) at position \fIpos\fR (in contents coordinates). If \fIpara\fR is not null, \fIpara\fR is set to this paragraph. If there is no character at \fIpos\fR, -1 is returned..SH "void QTextEdit::clear ()\fC [virtual slot]\fR"Deletes all the text in the text edit..PPSee also cut(), removeSelectedText() and text..SH "void QTextEdit::clearParagraphBackground ( int para )\fC [virtual slot]\fR"Clears the background color of the paragraph \fIpara\fR, so that the default color is used again..SH "QColor QTextEdit::color () const"Returns the color of the current format..PPSee also setColor() and paper..SH "QString QTextEdit::context () const"Returns the context of the edit. The context is a path which the text edit's QMimeSourceFactory uses to resolve the locations of files and images..PPSee also text..PPExamples:.)l helpviewer/helpwindow.cpp and qdir/qdir.cpp..SH "void QTextEdit::copy ()\fC [virtual slot]\fR"Copies any selected text (from selection 0) to the clipboard..PPSee also hasSelectedText and copyAvailable()..SH "void QTextEdit::copyAvailable ( bool yes )\fC [signal]\fR"This signal is emitted when text is selected or de-selected in the text edit..PPWhen text is selected this signal will be emitted with \fIyes\fR set to TRUE. If no text has been selected or if the selected text is de-selected this signal is emitted with \fIyes\fR set to FALSE..PPIf \fIyes\fR is TRUE then copy() can be used to copy the selection to the clipboard. If \fIyes\fR is FALSE then copy() does nothing..PPSee also selectionChanged()..SH "QPopupMenu * QTextEdit::createPopupMenu ( const QPoint & pos )\fC [virtual protected]\fR"This function is called to create a right mouse button popup menu at the document position \fIpos\fR. 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..SH "QPopupMenu * QTextEdit::createPopupMenu ()\fC [virtual protected]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPThis 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..SH "void QTextEdit::currentAlignmentChanged ( int a )\fC [signal]\fR"This signal is emitted if the alignment of the current paragraph has changed..PPThe new alignment is \fIa\fR..PPSee also setAlignment()..SH "void QTextEdit::currentColorChanged ( const QColor & c )\fC [signal]\fR"This signal is emitted if the color of the current format has changed..PPThe new color is \fIc\fR..PPSee also setColor()..SH "void QTextEdit::currentFontChanged ( const QFont & f )\fC [signal]\fR"This signal is emitted if the font of the current format has changed..PPThe new font is \fIf\fR..PPSee also setCurrentFont()..SH "void QTextEdit::currentVerticalAlignmentChanged ( VerticalAlignment a )\fC [signal]\fR"This signal is emitted if the vertical alignment of the current format has changed.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -