The QPlainTextEdit 類提供用於編輯和顯示純文本的 Widget。 更多...
| 頭: | #include <QPlainTextEdit> |
| qmake: | QT += widgets |
| Since: | Qt 4.4 |
| 繼承: | QAbstractScrollArea |
| enum | LineWrapMode { NoWrap, WidgetWidth } |
|
|
| QPlainTextEdit (QWidget * parent = Q_NULLPTR) | |
| QPlainTextEdit (const QString & text , QWidget * parent = Q_NULLPTR) | |
| virtual | ~QPlainTextEdit () |
| QString | anchorAt (const QPoint & pos ) const |
| bool | backgroundVisible () const |
| int | blockCount () const |
| bool | canPaste () const |
| bool | centerOnScroll () const |
| QMenu * | createStandardContextMenu () |
| QMenu * | createStandardContextMenu (const QPoint & position ) |
| QTextCharFormat | currentCharFormat () const |
| QTextCursor | cursorForPosition (const QPoint & pos ) const |
| QRect | cursorRect (const QTextCursor & cursor ) const |
| QRect | cursorRect () const |
| int | cursorWidth () const |
| QTextDocument * | document () const |
| QString | documentTitle () const |
| void | ensureCursorVisible () |
| QList<QTextEdit::ExtraSelection> | extraSelections () const |
| bool | find (const QString & exp , QTextDocument::FindFlags options = QTextDocument::FindFlags()) |
| bool | find (const QRegExp & exp , QTextDocument::FindFlags options = QTextDocument::FindFlags()) |
| bool | isReadOnly () const |
| bool | isUndoRedoEnabled () const |
| LineWrapMode | lineWrapMode () const |
| virtual QVariant | loadResource (int type , const QUrl & name ) |
| int | maximumBlockCount () const |
| void | mergeCurrentCharFormat (const QTextCharFormat & modifier ) |
| void | moveCursor (QTextCursor::MoveOperation operation , QTextCursor::MoveMode mode = QTextCursor::MoveAnchor) |
| bool | overwriteMode () const |
| QString | placeholderText () const |
| void | print (QPagedPaintDevice * printer ) const |
| void | setBackgroundVisible (bool visible ) |
| void | setCenterOnScroll (bool enabled ) |
| void | setCurrentCharFormat (const QTextCharFormat & format ) |
| void | setCursorWidth (int width ) |
| void | setDocument (QTextDocument * document ) |
| void | setDocumentTitle (const QString & title ) |
| void | setExtraSelections (const QList<QTextEdit::ExtraSelection> & selections ) |
| void | setLineWrapMode (LineWrapMode mode ) |
| void | setMaximumBlockCount (int maximum ) |
| void | setOverwriteMode (bool overwrite ) |
| void | setPlaceholderText (const QString & placeholderText ) |
| void | setReadOnly (bool ro ) |
| void | setTabChangesFocus (bool b ) |
| void | setTabStopWidth (int width ) |
| void | setTextCursor (const QTextCursor & cursor ) |
| void | setTextInteractionFlags (Qt::TextInteractionFlags flags ) |
| void | setUndoRedoEnabled (bool enable ) |
| void | setWordWrapMode (QTextOption::WrapMode policy ) |
| bool | tabChangesFocus () const |
| int | tabStopWidth () const |
| QTextCursor | textCursor () const |
| Qt::TextInteractionFlags | textInteractionFlags () const |
| QString | toPlainText () const |
| QTextOption::WrapMode | wordWrapMode () const |
| virtual QVariant | inputMethodQuery (Qt::InputMethodQuery property ) const |
| void | appendHtml (const QString & html ) |
| void | appendPlainText (const QString & text ) |
| void | centerCursor () |
| void | clear () |
| void | copy () |
| void | cut () |
| void | insertPlainText (const QString & text ) |
| void | paste () |
| void | redo () |
| void | selectAll () |
| void | setPlainText (const QString & text ) |
| void | undo () |
| void | zoomIn (int range = 1) |
| void | zoomOut (int range = 1) |
| void | blockCountChanged (int newBlockCount ) |
| void | copyAvailable (bool yes ) |
| void | cursorPositionChanged () |
| void | modificationChanged (bool changed ) |
| void | redoAvailable (bool available ) |
| void | selectionChanged () |
| void | textChanged () |
| void | undoAvailable (bool available ) |
| void | updateRequest (const QRect & rect , int dy ) |
| QRectF | blockBoundingGeometry (const QTextBlock & block ) const |
| QRectF | blockBoundingRect (const QTextBlock & block ) const |
| virtual bool | canInsertFromMimeData (const QMimeData * source ) const |
| QPointF | contentOffset () const |
| virtual QMimeData * | createMimeDataFromSelection () const |
| QTextBlock | firstVisibleBlock () const |
| QAbstractTextDocumentLayout::PaintContext | getPaintContext () const |
| virtual void | insertFromMimeData (const QMimeData * source ) |
| virtual void | changeEvent (QEvent * e ) |
| virtual void | contextMenuEvent (QContextMenuEvent * event ) |
| virtual void | dragEnterEvent (QDragEnterEvent * e ) |
| virtual void | dragLeaveEvent (QDragLeaveEvent * e ) |
| virtual void | dragMoveEvent (QDragMoveEvent * e ) |
| virtual void | dropEvent (QDropEvent * e ) |
| virtual void | focusInEvent (QFocusEvent * e ) |
| virtual bool | focusNextPrevChild (bool next ) |
| virtual void | focusOutEvent (QFocusEvent * e ) |
| virtual void | inputMethodEvent (QInputMethodEvent * e ) |
| virtual void | keyPressEvent (QKeyEvent * e ) |
| virtual void | keyReleaseEvent (QKeyEvent * e ) |
| virtual void | mouseDoubleClickEvent (QMouseEvent * e ) |
| virtual void | mouseMoveEvent (QMouseEvent * e ) |
| virtual void | mousePressEvent (QMouseEvent * e ) |
| virtual void | mouseReleaseEvent (QMouseEvent * e ) |
| virtual void | paintEvent (QPaintEvent * e ) |
| virtual void | resizeEvent (QResizeEvent * e ) |
| virtual void | scrollContentsBy (int dx , int dy ) |
| virtual void | showEvent ( QShowEvent * ) |
| virtual void | wheelEvent (QWheelEvent * e ) |
The QPlainTextEdit 類提供用於編輯和顯示純文本的 Widget。
QPlainTextEdit 是支持純文本的高級查看器/編輯器。經優化,能處理大文檔和快速響應用戶輸入。
QPlainText 使用非常相同的技術和概念,如 QTextEdit ,但為純文本處理進行瞭優化。
QPlainTextEdit 工作於段落和字符。段落是自動換行以擬閤 Widget 寬度的格式化字符串。默認情況下,當讀取純文本時,一個換行符錶示一個段落。文檔由零個或多個段落組成。段落由硬換行符分隔。段落中的每個字符有其自己的屬性 (例如:字體和顔色)。
鼠標光標的形狀在 QPlainTextEdit is Qt::IBeamCursor 默認情況下。可以改變透過 viewport () 的光標特性。
設置或替代文本使用 setPlainText () 刪除並替換現有文本,把文本傳遞給 setPlainText ().
插入文本可用使用 QTextCursor 類或使用方便函數 insertPlainText (), appendPlainText () 或 paste ().
默認情況下,文本編輯在空白處自動換行以擬閤在文本編輯 Widget 內。 setLineWrapMode () 函數用於指定想要的換行種類, WidgetWidth or NoWrap 若不想要任何換行。若使用自動換行到 Widget 的寬度 WidgetWidth ,可以指定是在空白處斷開還是在任何地方斷開采用 setWordWrapMode ().
The find () 函數可以用於在文本中查找和選擇給定字符串。
若想要限製段落總數在 QPlainTextEdit , as it is for example useful in a log viewer, then you can use the maximumBlockCount 特性。組閤 setMaximumBlockCount () 和 appendPlainText () turns QPlainTextEdit into an efficient viewer for log text. The scrolling can be reduced with the centerOnScroll () 特性,使日誌查看器甚至更快。文本可以按有限方式被格式化,使用語法高亮器 (見下文),或追加 html 格式文本采用 appendHtml (). While QPlainTextEdit does not support complex rich text rendering with tables and floats, it does support limited paragraph-based formatting that you may need in a log viewer.
當 QPlainTextEdit 被隻讀使用時,鍵綁定僅限於導航,且隻可以采用鼠標選擇文本:
| 按鍵 | 動作 |
|---|---|
| Qt::UpArrow | 嚮上移動一行。 |
| Qt::DownArrow | 嚮下移動一行。 |
| Qt::LeftArrow | 嚮左移動一字符。 |
| Qt::RightArrow | 嚮右移動一字符。 |
| PageUp | 嚮上移動一 (視口) 頁。 |
| PageDown | 嚮下移動一 (視口) 頁。 |
| Home | 移至文本起始。 |
| End | 移至文本末尾。 |
| Alt+Wheel | 水平捲動頁麵 (Wheel 是鼠標滾輪)。 |
| Ctrl+Wheel | 縮放文本。 |
| Ctrl+A | 選擇所有文本。 |
所有信息有關使用 QPlainTextEdit 作為顯示 Widget 在此也適用。
文本選擇的處理通過 QTextCursor 類,提供創建選擇、檢索文本內容或刪除選定的功能。可以檢索對應用戶可見光標的對象使用 textCursor () method. If you want to set a selection in QPlainTextEdit just create one on a QTextCursor 對象然後使該光標成為可見光標使用 setCursor ()。選定可以被拷貝到剪貼闆采用 copy (),或剪切到剪貼闆采用 cut ()。可以選擇整個文本使用 selectAll ().
QPlainTextEdit 保持 QTextDocument 對象,可以被檢索使用 document () 方法。還可以設置自己的文檔對象使用 setDocument (). QTextDocument 發射 textChanged () 信號若文本改變,且它還提供 isModified() 函數,返迴 true 若文本在加載或采用 false 作為自變量最後調用 setModified 後被修改。此外,它提供撤消和重做方法。
就像 QTextEdit , QPlainTextEdit works together with QSyntaxHighlighter .
為編輯而實現的鍵綁定列錶:
| 按鍵 | 動作 |
|---|---|
| Backspace | 刪除光標左側字符。 |
| Delete | 刪除光標右側字符。 |
| Ctrl+C | 把選中文本拷貝到剪貼闆。 |
| Ctrl+Insert | 把選中文本拷貝到剪貼闆。 |
| Ctrl+K | 刪除到行尾。 |
| Ctrl+V | 把剪貼闆文本粘貼到文本編輯中。 |
| Shift+Insert | 把剪貼闆文本粘貼到文本編輯中。 |
| Ctrl+X | 刪除選中文本並把它拷貝到剪貼闆。 |
| Shift+Delete | 刪除選中文本並把它拷貝到剪貼闆。 |
| Ctrl+Z | 撤消上一操作。 |
| Ctrl+Y | 重做上一操作。 |
| LeftArrow | 左移光標一字符。 |
| Ctrl+LeftArrow | 把光標左移一單詞。 |
| RightArrow | 右移光標一字符。 |
| Ctrl+RightArrow | 把光標右移一單詞。 |
| UpArrow | 上移光標一行。 |
| Ctrl+UpArrow | 把光標上移一單詞。 |
| DownArrow | 下移光標一行。 |
| Ctrl+Down Arrow | 把光標下移一單詞。 |
| PageUp | 把光標上移一頁。 |
| PageDown | 把光標下移一頁。 |
| Home | 把光標移到行開頭。 |
| Ctrl+Home | 把光標移到文本開頭。 |
| End | 把光標移到行尾。 |
| Ctrl+End | 把光標移到文本末尾。 |
| Alt+Wheel | 水平捲動頁麵 (Wheel 是鼠標滾輪)。 |
| Ctrl+Wheel | 縮放文本。 |
要選擇 (標記) 文本,在按住 Shift 鍵的同時按下某一移動擊鍵,例如, Shift+Right Arrow 將選擇右側字符,而 Shift+Ctrl+Right Arrow 將選擇右側單詞,等等。
QPlainTextEdit is a thin class, implemented by using most of the technology that is behind QTextEdit and QTextDocument 。其性能優於 QTextEdit 主要源於使用瞭不同且簡化的文本布局,稱為 QPlainTextDocumentLayout 在文本文檔 (見 QTextDocument::setDocumentLayout ())。純文本文檔布局不支持錶格、嵌入框架,及 將準確像素高度計算,分彆替換為逐行、逐段滾動方式 。這使之處理顯著更大文檔成為可能,且仍然能在實時啓用換行的情況下重置編輯器大小。它還可以製作快速日誌查看器 (見 setMaximumBlockCount ()).
另請參閱 QTextDocument , QTextCursor , 應用程序範例 , 代碼編輯器範例 , 句法高亮器範例 ,和 富文本處理 .
| 常量 | 值 |
|---|---|
QPlainTextEdit::NoWrap
|
0
|
QPlainTextEdit::WidgetWidth
|
1
|
此特性保持在文檔區域外調色闆背景是否可見
若設為 true,純文本編輯將在由文本文檔未覆蓋的視口區域中描繪調色闆背景。否則,若設為 false,不描繪。特徵使之是可能的,以供用戶視覺區分文檔區域、采用調色闆基色的描繪、及不被任何文檔所覆蓋的空區域。
默認為 false。
訪問函數:
| bool | backgroundVisible () const |
| void | setBackgroundVisible (bool visible ) |
此特性保持文檔文本塊數。
默認情況下,此特性在空文檔中包含 1 值。
訪問函數:
| int | blockCount () const |
此特性保持光標是否應居中屏幕
若設為 true,純文本編輯器將垂直捲動文檔,以使光標在視口中心可見。這還允許文本編輯,捲動到文檔末尾以下。否則,若設為 false,純文本編輯將捲動最小可能數量,以確保光標可見。相同算法將應用於任何新追加行透過 appendPlainText ().
默認為 false。
訪問函數:
| bool | centerOnScroll () const |
| void | setCenterOnScroll (bool enabled ) |
另請參閱 centerCursor () 和 ensureCursorVisible ().
此特性指定光標的寬度 (以像素為單位)。默認值為 1。
訪問函數:
| int | cursorWidth () const |
| void | setCursorWidth (int width ) |
此特性保持剖析自文本的文檔標題。
默認情況下,此特性包含空字符串。
訪問函數:
| QString | documentTitle () const |
| void | setDocumentTitle (const QString & title ) |
此特性保持換行模式
默認模式為 WidgetWidth 促使單詞在文本編輯右邊緣換行。換行發生在空白處,保持整個單詞完整。若想要換行發生在單詞內,使用 setWordWrapMode ().
訪問函數:
| LineWrapMode | lineWrapMode () const |
| void | setLineWrapMode (LineWrapMode mode ) |
此特性保持用於文檔塊的限製。
指定文檔可能擁有的最大塊數。若采用此特性的指定文檔有更多塊,則塊被移除從文檔開頭。
文檔的負值 (或零值) 指定可能包含無限數量的塊。
默認值為 0。
注意:設置此特性會把限製立即應用於文檔內容。設置此特性還會禁用撤消重做曆史。
訪問函數:
| int | maximumBlockCount () const |
| void | setMaximumBlockCount (int maximum ) |
此特性保持由用戶鍵入的文本是否覆蓋現有文本
就像很多文本編輯器,可以配置純文本編輯器 Widget 采用由用戶錄入的新文本以插入 (或覆寫) 現有文本。
若此特性為
true
,以新文本逐字符覆寫現有文本;否則,在光標位置處插入文本,置換現有文本。
默認情況下,此特性為
false
(新文本不覆寫現有文本)。
訪問函數:
| bool | overwriteMode () const |
| void | setOverwriteMode (bool overwrite ) |
此特性保持編輯器占位符文本
設置此特性將使編輯器顯示變灰占位符文本隻要 document () 為空。
默認情況下,此特性包含空字符串。
該特性在 Qt 5.3 引入。
訪問函數:
| QString | placeholderText () const |
| void | setPlaceholderText (const QString & placeholderText ) |
另請參閱 document ().
此特性獲取並設置純文本編輯器的內容。先前內容被移除,且撤消/重做曆史被重置,當設置此特性時。
默認情況下,對於沒有內容的編輯器,此特性包含空字符串。
訪問函數:
| QString | toPlainText () const |
| void | setPlainText (const QString & text ) |
通知程序信號:
| void | textChanged () |
此特性保持文本編輯是否為隻讀
在隻讀文本編輯中,用戶隻能導航文本和選擇文本;修改文本是不可能的。
此特性默認為 false。
訪問函數:
| bool | isReadOnly () const |
| void | setReadOnly (bool ro ) |
此特性保持是否 Tab 改變聚焦 (或接受作為輸入)
在某些場閤,文本編輯不應該允許用戶輸入 Tab (製錶符) 或改變縮進使用 Tab 鍵,因為這會打斷聚焦鏈。默認為 false。
訪問函數:
| bool | tabChangesFocus () const |
| void | setTabChangesFocus (bool b ) |
This property holds the tab stop width in pixels
默認情況下,此特性包含 80 的值。
訪問函數:
| int | tabStopWidth () const |
| void | setTabStopWidth (int width ) |
指定標簽應如何與用戶輸入交互,若它顯示文本。
若標誌包含 Qt::LinksAccessibleByKeyboard or Qt::TextSelectableByKeyboard 那麼聚焦策略還被自動設為 Qt::ClickFocus .
默認值取決於 QPlainTextEdit 是隻讀或可編輯。
訪問函數:
| Qt::TextInteractionFlags | textInteractionFlags () const |
| void | setTextInteractionFlags (Qt::TextInteractionFlags flags ) |
此特性保持是否啓用瞭撤消和重做
用戶纔能撤消 (或重做) 動作,若此屬性為 true,且存在可以撤消 (或重做) 的動作。
默認情況下,此特性為
true
.
訪問函數:
| bool | isUndoRedoEnabled () const |
| void | setUndoRedoEnabled (bool enable ) |
此特性保持模式 QPlainTextEdit 會使用,當按單詞換行文本時
默認情況下,此特性被設為 QTextOption::WrapAtWordBoundaryOrAnywhere .
訪問函數:
| QTextOption::WrapMode | wordWrapMode () const |
| void | setWordWrapMode (QTextOption::WrapMode policy ) |
另請參閱 QTextOption::WrapMode .
構造空的 QPlainTextEdit 采用父級 parent .
構造 QPlainTextEdit 采用父級 parent 。文本編輯將顯示純文本 text .
[虛擬]
QPlainTextEdit::
~QPlainTextEdit
()
析構函數。
返迴錨點的引用在位置 pos ,或空字符串若該點處不存在錨點。
該函數在 Qt 4.7 引入。
[slot]
void
QPlainTextEdit::
appendHtml
(const
QString
&
html
)
追加新段落采用 html 到文本編輯末尾。
[slot]
void
QPlainTextEdit::
appendPlainText
(const
QString
&
text
)
追加新段落采用 text 到文本編輯末尾。
另請參閱 appendHtml ().
[protected]
QRectF
QPlainTextEdit::
blockBoundingGeometry
(const
QTextBlock
&
block
) const
返迴邊界矩形對於文本 block 按內容坐標。平移矩形采用 contentOffset () 以獲取視口的視覺坐標。
另請參閱 firstVisibleBlock () 和 blockBoundingRect ().
[protected]
QRectF
QPlainTextEdit::
blockBoundingRect
(const
QTextBlock
&
block
) const
返迴邊界矩形對於文本 block 按塊自己的坐標。
另請參閱 blockBoundingGeometry ().
[signal]
void
QPlainTextEdit::
blockCountChanged
(
int
newBlockCount
)
此信號被發射每當塊計數改變時。新的塊計數被傳入 newBlockCount .
[virtual protected]
bool
QPlainTextEdit::
canInsertFromMimeData
(const
QMimeData
*
source
) const
此函數返迴
true
若 MIME (多用途 Internet 郵件擴展) 數據對象內容的指定是通過
source
,可以解碼並插入進文檔。例如,會調用它在拖拽操作期間,鼠標進入此 Widget,且有必要確定它是否可能接受拖拽時。
返迴是否可以把文本從剪貼闆粘貼到 textedit。
[slot]
void
QPlainTextEdit::
centerCursor
()
捲動文檔以使光標垂直居中。
另請參閱 ensureCursorVisible () 和 centerOnScroll .
[virtual protected]
void
QPlainTextEdit::
changeEvent
(
QEvent
*
e
)
重實現自 QWidget::changeEvent ().
[slot]
void
QPlainTextEdit::
clear
()
刪除文本編輯中的所有文本。
Note that the undo/redo history is cleared by this function.
另請參閱 cut () 和 setPlainText ().
[protected]
QPointF
QPlainTextEdit::
contentOffset
() const
返迴視口坐標中的內容原點。
純文本編輯內容的原點,始終位於第一可見文本塊左上角。內容偏移不等於 (0, 0) 當水平捲動文本時,或當第一可見塊部分捲動齣屏幕時 (即:可見文本不始於第一可見塊的第一行,或當第一可見塊不是首個塊且編輯器顯示邊距時)。
另請參閱 firstVisibleBlock (), horizontalScrollBar (),和 verticalScrollBar ().
[virtual protected]
void
QPlainTextEdit::
contextMenuEvent
(
QContextMenuEvent
*
event
)
重實現自 QWidget::contextMenuEvent ().
展示標準上下文菜單,創建采用 createStandardContextMenu ().
若不想要文本編輯擁有上下文菜單,可以設置其 contextMenuPolicy to Qt::NoContextMenu 。若想要定製上下文菜單,重實現此函數。若想要擴展標準上下文菜單,重實現此函數,調用 createStandardContextMenu () 並擴展返迴菜單。
有關事件信息的傳遞是在 event 對象。
void MyQPlainTextEdit::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = createStandardContextMenu(); menu->addAction(tr("My Menu Item")); //... menu->exec(event->globalPos()); delete menu; }
[slot]
void
QPlainTextEdit::
copy
()
把任何選中文本拷貝到剪貼闆。
另請參閱 copyAvailable ().
[signal]
void
QPlainTextEdit::
copyAvailable
(
bool
yes
)
此信號被發射當在文本編輯中選擇或取消選擇文本時。
當有文本被選中時,此信號會被發射采用 yes 設為 true。若沒有文本被選中或選中文本被取消選擇,此信號被發射采用 yes 設為 false。
若 yes 為 True 則 copy () 可以用於把選定拷貝到剪貼闆。若 yes 為 false 則 copy () 什麼都不做。
另請參閱 selectionChanged ().
[virtual protected]
QMimeData
*QPlainTextEdit::
createMimeDataFromSelection
() const
此函數返迴錶示文本編輯當前選定內容的新的 MIME 數據對象。它被調用當需要將選定封裝成新的 QMimeData 對象;例如,當開始拖放操作或將數據拷貝到剪貼闆時。
若重實現此函數,注意,所有權對於返迴的 QMimeData 對象被傳遞給調用者。可以檢索選定通過使用 textCursor () 函數。
此函數創建要展示的標準上下文菜單,當用戶采用鼠標右鍵點擊文本編輯時。它被調用從默認 contextMenuEvent () 處理程序。將彈齣菜單的所有權轉移給調用者。
推薦使用 createStandardContextMenu( QPoint ) 版本,啓用用戶點擊位置敏感動作。
此函數創建要展示的標準上下文菜單,當用戶采用鼠標右鍵點擊文本編輯時。它被調用從默認 contextMenuEvent () 處理程序,且它獲取 position 在文檔坐標中 (當鼠標點擊時)。這可以啓用用戶點擊位置敏感動作。將彈齣菜單的所有權轉移給調用者。
該函數在 Qt 5.5 引入。
返迴插入新文本時使用的字符格式。
另請參閱 setCurrentCharFormat ().
返迴 QTextCursor 在位置 pos (在視口坐標中)。
[signal]
void
QPlainTextEdit::
cursorPositionChanged
()
此信號被發射每當光標位置改變時。
返迴矩形 (在視口坐標中) 包括 cursor .
返迴包括文本編輯光標的矩形 (在視口坐標中)。
[slot]
void
QPlainTextEdit::
cut
()
把選中文本拷貝到剪貼闆,並將其從文本編輯中刪除。
若沒有選中文本,什麼都不發生。
返迴底層文檔指針。
另請參閱 setDocument ().
[virtual protected]
void
QPlainTextEdit::
dragEnterEvent
(
QDragEnterEvent
*
e
)
重實現自 QWidget::dragEnterEvent ().
[virtual protected]
void
QPlainTextEdit::
dragLeaveEvent
(
QDragLeaveEvent
*
e
)
重實現自 QWidget::dragLeaveEvent ().
[virtual protected]
void
QPlainTextEdit::
dragMoveEvent
(
QDragMoveEvent
*
e
)
重實現自 QWidget::dragMoveEvent ().
[virtual protected]
void
QPlainTextEdit::
dropEvent
(
QDropEvent
*
e
)
重實現自 QWidget::dropEvent ().
通過捲動文本編輯確保光標是可見的,若有必要。
另請參閱 centerCursor () 和 centerOnScroll .
返迴先前設置的額外選定。
另請參閱 setExtraSelections ().
查找下一齣現為字符串
exp
,使用給定
options
。返迴
true
if
exp
被發現且更改光標到選擇匹配;否則返迴
false
.
這是重載函數。
查找匹配正則錶達式的下一齣現 exp ,使用給定 options 。 QTextDocument::FindCaseSensitively 選項被忽略對於此重載,使用 QRegExp::caseSensitivity 代替。
返迴
true
若找到匹配並把光標改為選擇匹配;否則返迴
false
.
該函數在 Qt 5.3 引入。
[protected]
QTextBlock
QPlainTextEdit::
firstVisibleBlock
() const
返迴第一可見塊。
另請參閱 blockBoundingRect ().
[virtual protected]
void
QPlainTextEdit::
focusInEvent
(
QFocusEvent
*
e
)
重實現自 QWidget::focusInEvent ().
[virtual protected]
bool
QPlainTextEdit::
focusNextPrevChild
(
bool
next
)
重實現自 QWidget::focusNextPrevChild ().
[virtual protected]
void
QPlainTextEdit::
focusOutEvent
(
QFocusEvent
*
e
)
重實現自 QWidget::focusOutEvent ().
[protected]
QAbstractTextDocumentLayout::PaintContext
QPlainTextEdit::
getPaintContext
() const
返迴描繪上下文為 viewport (),纔有用當重實現 paintEvent ().
[virtual protected]
void
QPlainTextEdit::
inputMethodEvent
(
QInputMethodEvent
*
e
)
重實現自 QWidget::inputMethodEvent ().
[虛擬]
QVariant
QPlainTextEdit::
inputMethodQuery
(
Qt::InputMethodQuery
property
) const
重實現自 QWidget::inputMethodQuery ().
[virtual protected]
void
QPlainTextEdit::
insertFromMimeData
(const
QMimeData
*
source
)
此函數插入 MIME (多用途 Internet 郵件擴展) 數據對象的內容,指定通過 source ,進當前光標位置處的文本編輯。會調用它,每當因剪貼闆粘貼操作插入文本時 (或當文本編輯接受來自拖放操作的數據時)。
[slot]
void
QPlainTextEdit::
insertPlainText
(const
QString
&
text
)
方便槽插入 text 在當前光標位置。
它相當於
edit->textCursor().insertText(text);
[virtual protected]
void
QPlainTextEdit::
keyPressEvent
(
QKeyEvent
*
e
)
重實現自 QWidget::keyPressEvent ().
[virtual protected]
void
QPlainTextEdit::
keyReleaseEvent
(
QKeyEvent
*
e
)
重實現自 QWidget::keyReleaseEvent ().
[虛擬]
QVariant
QPlainTextEdit::
loadResource
(
int
type
, const
QUrl
&
name
)
加載指定資源通過給定 type and name .
此函數是擴展對於 QTextDocument::loadResource ().
另請參閱 QTextDocument::loadResource ().
閤並指定特性由 modifier 進當前字符格式通過調用 QTextCursor::mergeCharFormat 在編輯器光標。若編輯器擁有選定,則特性對於 modifier 被直接應用到選定。
另請參閱 QTextCursor::mergeCharFormat ().
[signal]
void
QPlainTextEdit::
modificationChanged
(
bool
changed
)
此信號被發射每當文檔的內容以影響修改狀態的方式更改時。若 changed 為 true,文檔已被修改;否則為 false。
例如:調用文檔 setModified(false),然後插入文本導緻發射信號。若撤消該操作,導緻文檔返迴其原始未修改狀態,將再次發射信號。
[virtual protected]
void
QPlainTextEdit::
mouseDoubleClickEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mouseDoubleClickEvent ().
[virtual protected]
void
QPlainTextEdit::
mouseMoveEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mouseMoveEvent ().
[virtual protected]
void
QPlainTextEdit::
mousePressEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mousePressEvent ().
[virtual protected]
void
QPlainTextEdit::
mouseReleaseEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mouseReleaseEvent ().
移動光標通過履行給定 operation .
若 mode is QTextCursor::KeepAnchor ,光標選擇由它移動覆蓋的文本。這與用戶達成的效果相同,當按下 Shift 鍵和采用光標鍵移動光標時。
另請參閱 QTextCursor::movePosition ().
[virtual protected]
void
QPlainTextEdit::
paintEvent
(
QPaintEvent
*
e
)
重實現自 QWidget::paintEvent ().
[slot]
void
QPlainTextEdit::
paste
()
把剪貼闆文本粘貼到文本編輯當前光標位置處。
若剪貼闆中沒有文本,什麼都不發生。
要改變此函數的行為,即,要修改什麼 QPlainTextEdit 可以粘貼及如何粘貼,重實現虛擬 canInsertFromMimeData () 和 insertFromMimeData () 函數。
方便函數以將文本編輯文檔打印到給定 printer . This is equivalent to calling the print method on the document directly except that this function also supports QPrinter::Selection as print range.
另請參閱 QTextDocument::print ().
[slot]
void
QPlainTextEdit::
redo
()
重做上一操作。
若沒有要重做的操 (即:在撤消/重做曆史中沒有重做步驟),則什麼都不發生。
另請參閱 undo ().
[signal]
void
QPlainTextEdit::
redoAvailable
(
bool
available
)
此信號被發射,每當重做操作變為可用時 ( available 為 True) 或不可用 ( available 為 false)。
[virtual protected]
void
QPlainTextEdit::
resizeEvent
(
QResizeEvent
*
e
)
重實現自 QWidget::resizeEvent ().
[virtual protected]
void
QPlainTextEdit::
scrollContentsBy
(
int
dx
,
int
dy
)
重實現自 QAbstractScrollArea::scrollContentsBy ().
[slot]
void
QPlainTextEdit::
selectAll
()
選擇所有文本。
另請參閱 copy (), cut (),和 textCursor ().
[signal]
void
QPlainTextEdit::
selectionChanged
()
此信號發射,每當選定改變時。
另請參閱 copyAvailable ().
把新文本插入時使用的字符格式設為 format 通過調用 QTextCursor::setCharFormat () 在編輯器光標。若編輯器擁有選定,則把字符格式直接應用到選定。
另請參閱 currentCharFormat ().
使 document 文本編輯器的新文檔。
父級 QObject 文檔的提供者仍然是對象的所有者。若當前文檔是文本編輯器的子級,則將其刪除。
文檔必須具有文檔布局,繼承 QPlainTextDocumentLayout (見 QTextDocument::setDocumentLayout ()).
另請參閱 document ().
此函數允許采用給定顔色臨時標記某些文檔區域,指定通過 selections 。例如:在編程編輯器中這可以是有用的,采用給定背景色標記整行文本以指示斷點的存在。
另請參閱 QTextEdit::ExtraSelection and extraSelections ().
[slot]
void
QPlainTextEdit::
setPlainText
(const
QString
&
text
)
把文本編輯的文本更改為字符串 text 。移除任何以前文本。
text 被解釋成純文本。
Note that the undo/redo history is cleared by this function.
注意: setter 函數對於特性 plainText .
另請參閱 toPlainText ().
設置可見 cursor .
另請參閱 textCursor ().
[virtual protected]
void
QPlainTextEdit::
showEvent
(
QShowEvent *
)
重實現自 QWidget::showEvent ().
[signal]
void
QPlainTextEdit::
textChanged
()
此信號被發射每當文檔內容改變時;例如,當插入 (或刪除) 文本 (或應用格式) 時。
注意: 通知程序信號對於特性 plainText .
返迴副本為 QTextCursor 錶示當前可見光標。注意:改變返迴光標不影響 QPlainTextEdit 的光標; 使用 setTextCursor () 以更新可見光標。
另請參閱 setTextCursor ().
把文本編輯的文本作為純文本返迴。
注意: getter 函數對於特性 plainText .
另請參閱 QPlainTextEdit::setPlainText ().
[slot]
void
QPlainTextEdit::
undo
()
撤消上一操作。
若沒有要撤消的操作 (即:撤消/重做曆史中沒有撤消步驟),什麼都不發生。
另請參閱 redo ().
[signal]
void
QPlainTextEdit::
undoAvailable
(
bool
available
)
此信號被發射每當撤消操作變為可用 ( available 為 True) 或不可用 ( available 為 false)。
[signal]
void
QPlainTextEdit::
updateRequest
(const
QRect
&
rect
,
int
dy
)
此信號被發射當文本文檔需要更新指定 rect 。若文本被捲動, rect 將覆蓋整個視口區域。若文本被垂直捲動, dy 攜帶視口被捲動的像素數量。
信號的目的是在純文本編輯子類中支持額外 Widget,如:展示行號、斷點或其它額外信息。
[virtual protected]
void
QPlainTextEdit::
wheelEvent
(
QWheelEvent
*
e
)
重實現自 QWidget::wheelEvent ().
[slot]
void
QPlainTextEdit::
zoomIn
(
int
range
= 1)
放大文本通過使基字體大小 range 點變得更大並將所有字體大小重新計算成新大小。這不會改變任何圖像大小。
另請參閱 zoomOut ().
[slot]
void
QPlainTextEdit::
zoomOut
(
int
range
= 1)
這是重載函數。
縮小文本通過使基字體大小 range 點變得更小並將所有字體大小重新計算成新大小。這不會改變任何圖像大小。
另請參閱 zoomIn ().