QLineEdit Widget 是一行文本编辑器。 更多...
继承 QWidget .
QLineEdit Widget 是一行文本编辑器。
A line edit allows the user to enter and edit a single line of plain text with a useful collection of editing functions, including undo and redo, cut and paste, and drag and drop.
通过改变 echoMode () of a line edit, it can also be used as a "write-only" field, for inputs such as passwords.
可以把文本长度约束到 maxLength (). The text can be arbitrarily constrained using a validator () 或 inputMask (), or both. When switching between a validator and an input mask on the same line edit, it is best to clear the validator or input mask to prevent undefined behavior.
相关类 QTextEdit which allows multi-line, rich text editing.
可以改变文本采用 setText () 或 insert ()。文本的检索采用 text (); the displayed text (which may be different, see EchoMode ) 的检索采用 displayText (). Text can be selected with setSelection () 或 selectAll (), and the selection can be cut (), copy () 和 paste ()。可以对齐文本采用 setAlignment ().
当文本改变时 textChanged () signal is emitted; when the text changes other than by calling setText () textEdited () signal is emitted; when the cursor is moved the cursorPositionChanged () signal is emitted; and when the Return or Enter key is pressed the returnPressed () signal is emitted.
When editing is finished, either because the line edit lost focus or Return/Enter is pressed the editingFinished () signal is emitted.
注意:若行编辑有设置验证器, returnPressed ()/ editingFinished () signals will only be emitted if the validator returns QValidator.Acceptable .
By default, QLineEdits have a frame as specified by the Windows and Motif style guides; you can turn it off by calling setFrame(false).
The default key bindings are described below. The line edit also provides a context menu (usually invoked by a right mouse click) that presents some of these editing options.
| Keypress | Action |
|---|---|
| Left Arrow | 左移光标一字符。 |
| Shift+Left Arrow | 左移并选择文本一字符。 |
| Right Arrow | 右移光标一字符。 |
| Shift+Right Arrow | 右移并选择文本一字符。 |
| 首页 | 把光标移到行开头。 |
| End | 把光标移到行尾。 |
| Backspace | 删除光标左侧字符。 |
| Ctrl+Backspace | 删除光标左侧的单词。 |
| Delete | 删除光标右侧字符。 |
| Ctrl+Delete | 删除光标右侧的单词。 |
| Ctrl+A | 选择所有。 |
| Ctrl+C | 把选中文本拷贝到剪贴板。 |
| Ctrl+Insert | 把选中文本拷贝到剪贴板。 |
| Ctrl+K | 删除到行尾。 |
| Ctrl+V | 将剪贴板文本粘贴到行编辑。 |
| Shift+Insert | 将剪贴板文本粘贴到行编辑。 |
| Ctrl+X | 删除选中文本并把它拷贝到剪贴板。 |
| Shift+Delete | 删除选中文本并把它拷贝到剪贴板。 |
| Ctrl+Z | 撤消上一操作。 |
| Ctrl+Y | 重做上一撤消操作。 |
Any other key sequence that represents a valid character, will cause the character to be inserted into the line edit.
|
A line edit shown in the Macintosh widget style . |
|
A line edit shown in the Windows XP widget style . |
|
A line edit shown in the Plastique widget style . |
This enum type describes how a line edit should display its contents.
| 常量 | 值 | 描述 |
|---|---|---|
| QLineEdit.Normal | 0 | Display characters as they are entered. This is the default. |
| QLineEdit.NoEcho | 1 | Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret. |
| QLineEdit.Password | 2 | Display asterisks instead of the characters actually entered. |
| QLineEdit.PasswordEchoOnEdit | 3 | Display characters as they are entered while editing otherwise display asterisks. |
另请参阅 setEchoMode () 和 echoMode ().
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
构造行编辑不采用文本。
最大文本长度被设为 32767 个字符。
parent 自变量被发送给 QWidget 构造函数。
另请参阅 setText () and setMaxLength ().
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
构造行编辑包含文本 contents .
The cursor position is set to the end of the line and the maximum text length to 32767 characters.
parent 和自变量被发送给 QWidget 构造函数。
另请参阅 text () and setMaxLength ().
If no text is selected, deletes the character to the left of the text cursor and moves the cursor one position to the left. If any text is selected, the cursor is moved to the beginning of the selected text and the selected text is deleted.
另请参阅 del_ ().
重实现自 QWidget.changeEvent ().
清零行编辑的内容。
另请参阅 setText () and insert ().
返回当前 QCompleter ,其提供补全。
该函数在 Qt 4.2 引入。
另请参阅 setCompleter ().
重实现自 QWidget.contextMenuEvent ().
展示标准上下文菜单,创建采用 createStandardContextMenu ().
If you do not want the line edit to have a context menu, you can set its contextMenuPolicy to Qt.NoContextMenu 。若 you want to customize the context menu, reimplement this function. If you want to extend the standard context menu, reimplement this function, call createStandardContextMenu () and extend the menu returned.
void LineEdit.contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = createStandardContextMenu(); menu->addAction(tr("My Menu Item")); //... menu->exec(event->globalPos()); delete menu; }
event parameter is used to obtain the position where the mouse cursor was when the event was generated.
另请参阅 setContextMenuPolicy ().
Copies the selected text to the clipboard, if there is any, and if echoMode () 是 Normal .
This function creates the standard context menu which is shown when the user clicks on the line edit with the right mouse button. It is called from the default contextMenuEvent () handler. The popup menu's ownership is transferred to the caller.
后移光标 steps 字符。若 mark is true each character moved over is added to the selection; if mark 为 False,清零选定。
另请参阅 cursorForward ().
前移光标 steps 字符。若 mark 为 true,每个移过字符会被添加到选定;若 mark 为 False,清零选定。
另请参阅 cursorBackward ().
返回光标位置在点 pos .
返回包括行编辑光标的矩形。
该函数在 Qt 4.4 引入。
将光标后移一单词。若 mark is true, the word is also selected.
另请参阅 cursorWordForward ().
将光标前移一单词。若 mark is true, the word is also selected.
另请参阅 cursorWordBackward ().
Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode () 是 Normal .
If the current validator disallows deleting the selected text, cut() will copy without deleting.
另请参阅 copy (), paste (),和 setValidator ().
If no text is selected, deletes the character to the right of the text cursor. If any text is selected, the cursor is moved to the beginning of the selected text and the selected text is deleted.
另请参阅 backspace ().
取消任何选中文本的选择。
另请参阅 setSelection () 和 selectAll ().
重实现自 QWidget.dragEnterEvent ().
重实现自 QWidget.dragLeaveEvent ().
重实现自 QWidget.dragMoveEvent ().
重实现自 QWidget.dropEvent ().
Moves the text cursor to the end of the line unless it is already there. If mark is true, text is selected towards the last position; otherwise, any selected text is unselected if the cursor is moved.
另请参阅 home ().
重实现自 QObject.event ().
重实现自 QWidget.focusInEvent ().
重实现自 QWidget.focusOutEvent ().
Returns the widget's text margins for left , top , right ,和 bottom .
该函数在 Qt 4.5 引入。
另请参阅 setTextMargins ().
Moves the text cursor to the beginning of the line unless it is already there. If mark is true, text is selected towards the first position; otherwise, any selected text is unselected if the cursor is moved.
另请参阅 end ().
初始化 option 采用值来自此 QLineEdit . This method is useful for subclasses when they need a QStyleOptionFrame or QStyleOptionFrameV2 , but don't want to fill in all the information themselves. This function will check the version of the QStyleOptionFrame and fill in the additional values for a QStyleOptionFrameV2 .
另请参阅 QStyleOption.initFrom ().
重实现自 QWidget.inputMethodEvent ().
重实现自 QWidget.inputMethodQuery ().
删除任何选中文本,插入 newText , and validates the result. If it is valid, it sets it as the new contents of the line edit.
重实现自 QWidget.keyPressEvent ().
转换给定键按下 event into a line edit action.
If Return or Enter is pressed and the current text is valid (or 可以是 使有效 by the validator), the signal returnPressed () 被发射。
The default key bindings are listed in the class's detailed description.
重实现自 QWidget.minimumSizeHint ().
返回行编辑最小尺寸。
The width returned is enough for at least one character.
重实现自 QWidget.mouseDoubleClickEvent ().
重实现自 QWidget.mouseMoveEvent ().
重实现自 QWidget.mousePressEvent ().
重实现自 QWidget.mouseReleaseEvent ().
重实现自 QWidget.paintEvent ().
Inserts the clipboard's text at the cursor position, deleting any selected text, providing the line edit is not 只读 .
If the end result would not be acceptable to the current validator , nothing happens.
重做上一操作,若重做 available .
Selects all the text (i.e. highlights it) and moves the cursor to the end. This is useful when a default value has been inserted because if the user types before clicking on the widget, the selected text will be deleted.
另请参阅 setSelection () 和 deselect ().
selectionStart() returns the index of the first selected character in the line edit or -1 if no text is selected.
另请参阅 selectedText ().
Sets this line edit to provide auto completions from the completer, c 。补全模式的设置使用 QCompleter.setCompletionMode ().
要使用 QCompleter 采用 QValidator or QLineEdit.inputMask , you need to ensure that the model provided to QCompleter contains valid entries. You can 使用 QSortFilterProxyModel to ensure that the QCompleter 's model contains only valid entries.
若 c == 0, setCompleter() removes the current completer, effectively disabling auto completion.
该函数在 Qt 4.2 引入。
另请参阅 completer () 和 QCompleter .
选择文本从位置 start and for length 个字符。负长度是允许的。
另请参阅 deselect (), selectAll (),和 selectedText ().
Sets the margins around the text inside the frame to have the sizes left , top , right ,和 bottom .
另请参阅 getTextMargins ().
该函数在 Qt 4.5 引入。
另请参阅 textMargins ().
设置 margins 围绕文本在框架内。
另请参阅 textMargins ().
该函数在 Qt 4.6 引入。
Sets this line edit to only accept input that the validator, v , will accept. This allows you to place any arbitrary constraints on the text which may be entered.
若 v == 0, setValidator() removes the current input validator. The initial setting is to have no input validator (i.e. any input is accepted up to maxLength ()).
另请参阅 validator (), QIntValidator , QDoubleValidator ,和 QRegExpValidator .
重实现自 QWidget.sizeHint ().
返回 Widget 的推荐尺寸。
The width returned, in pixels, is usually enough for about 15 to 20 characters.
返回 Widget 的文本边距。
该函数在 Qt 4.6 引入。
另请参阅 setTextMargins ().
撤消上一操作,若撤消 available . Deselects any current selection, and updates the selection start to the current cursor position.
Returns a pointer to the current input validator, or 0 if no validator has been set.
另请参阅 setValidator ().
This is the default overload of this signal.
This signal is emitted whenever the cursor moves. The previous position is given by old ,和新位置由 new .
另请参阅 setCursorPosition () 和 cursorPosition ().
This is the default overload of this signal.
This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. Note that if there is a validator () 或 inputMask () set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input follows the inputMask () 和 validator () 返回 QValidator.Acceptable .
This is the default overload of this signal.
This signal is emitted when the Return or Enter key is pressed. Note that if there is a validator () 或 inputMask () set on the line edit, the returnPressed() signal will only be emitted if the input follows the inputMask () 和 validator () 返回 QValidator.Acceptable .
This is the default overload of this signal.
此信号被发射每当选定改变。
另请参阅 hasSelectedText () 和 selectedText ().
This is the default overload of this signal.
此信号被发射每当文本改变时。 text 自变量是新文本。
不像 textEdited (), this signal is also emitted when the text is changed programmatically, for example, by calling setText ().
This is the default overload of this signal.
此信号被发射每当文本被编辑。 text 自变量是新文本。
不像 textChanged (), this signal is not emitted when the text is changed programmatically, for example, by calling setText ().