Qlineedit is the most common input class edit control following Qlabel and Qabstractbutton. As the name implies, it is a single-line edit control, often used to edit short information, such as user login information and password input. As an edit box, it has common editing actions, such as clear contents, copy copy, cut cut, paste paste, Redo Rudo, undo undo, Select SelectAll and set edit information SetText and delete Dselete and Del and BACKSPACE. According to the content and display of the edits, Qlineedit has different display modes: Qlineedit:::normal normal display, Qlineedi::P assword password display, that is, do not display content, Qlineedit:: NoEcho does not display any input, the common language password type, its password length all need to keep secret. Qlineedit::P Asswordechoonedit, which is the display of characters at the time of editing, is responsible for displaying the password type.
Qlineedit as a single-line edit box, its maximum input character length is displayed, generally obtained by maxlength () and set. The legitimacy of the input content can also be verified by the validator validator or the input mask inputmask, or both, in order to ensure the validity of the input content, to a large extent can avoid the difficulty of the input diversity check.
1. Qlineedit Important attributes
1) Echomode, decide how to input and display text to use, output display mode, Echomode echomode access, Setechomode (Echomode) to set
2) Acceptableinput:bool, whether the input satisfies the InputMask and validator authentication, is used to specify the content form of the edit box and so on, often with Setinpumask and setvalidator use. Access via Hasacceptableinput ().
3) Alignment: Edit the content of the boundary display situation, that is, how to display, the default is the left vertical center display Qalignment | Qt::alignvcenter, can be set by Setalignment (Qt::qalignment),
4) Cursorposition:int, this is the mouse property that represents the position of the mouse in the edit box. Set by Cursorposition () access, setcursorposition (int). The default value is 0
5) displaytext:qstring, is the current edit box display content. This property is related to the Echomode property, and if it is normal, its display is consistent with the text content, and if it is password or passwordechoonedit, it displays the same length of dots as the text "* * * * *". If it is noecho, this property is empty. Access via DisplayText ()
Here the text is still the specific input content. can be accessed and used.
6) Dragenabled:bool This property is related to mouse operation, is to grab whether it can be allowed, when there is a selected text file, the mouse is pressed and moved when the operation is allowed, through dragenabled () access, setdragenable (bool) to set.
7) Frame:bool This property flag whether the Lineedit itself is drawn into a frame frame. Set by Hasframe () access, setframe (BOOL). Common phenomena such as whether there is a border:
Property value is False
Property value is True
8) Hasselecttext:bool Indicates whether any text is selected. The edit box selection is a common operation, accessed through Hasselecttext (), and the selected text is stored in the Selecttext:qstring property, and SelectText () returns the corresponding value.
9) Inputmask:qstring This property is the input checksum code for the text box, which indicates the input format and number of inputs specified. Set by Setinputmask, or cancel this inoutmask if there is no parameter or an empty string "".
The following are the characters that you can use to set Inoutmask. A white space character, which is required if a character input is allowed but not required.
Character |
meaning |
A |
ASCII alphabetic characters are required and the value space is a-z,a-z |
A |
ASCII alphabetic characters are allowed but not required. |
N |
ASCII alphabetic characters are required. A-Z, A-Z, 0-9. |
N |
ASCII alphabetic characters are allowed but not required. |
X |
Any character can be required. |
X |
Any character is allowed, but not required. |
9 |
ASCII numbers are required. 0-9. |
0 |
ASCII numbers are allowed, but not required. |
D |
ASCII numbers are required. 1-9. |
D |
ASCII numbers are allowed, but not required (1-9). |
# |
ASCII numbers are allowed, but not required, to be or add-minus symbols. |
H |
Hexadecimal data characters are required. A-f, A-f, 0-9. |
H |
Hexadecimal data characters are allowed, but not required. |
B |
Binary data characters are required. 0-1. |
B |
Binary data characters are allowed, but not required. |
> |
All character letters are capitalized. |
< |
All character captions are lowercase. |
! |
Closes the case. |
\ |
Use \ to escape the above characters, if you need to display the above characters again. |
A check code has the above components, such as
IP address: 000.000.000.000;_ Empty character is _
MAC Address: HH:HH:HH:HH:HH:HH
Maxlength:int This property indicates the maximum number of characters that this edit box is allowed to enter. If the scene is cut, it will be truncated to a limited length. If a interception occurs, the previously selected character is Unselect released, the cursor position reverts to 0 and the beginning of the character is displayed. If this edit box has input mask input masks, the length of the mask determines the maximum length of the character, such as the maximum IP address of only 16 characters. Gets the setmaxlength (int) setting by MaxLength (). The maximum value is 32767
Modified:bool, this property indicates that the contents of the edit box have been modified by the user. One of the great uses of this property is that you can use this property if some input needs to be validated for modification. SetText () resets the modified flag. IsModified () Gets the state, setmodified (BOOL) sets this flag.
Readonly:bool Indicates whether this edit box is read-only, which is not writable, but can copy, drag, and drop text content without displaying the cursor. The default value for this property is false.
IsReadOnly () Gets the value of this property. Setreadonly (BOOL) sets this property value.
redoavailable:const BOOL Indicates whether the redo operation is available and is available when undo is executed from the left.
Undoavailable: Determines whether it can be executed, this action needs to be executed, the user needs to modify the contents of the edit box.
13), 14) property is not allowed to be set, which is expressed according to the final result of the operation.
Selecttext:conststring indicates that the text has been selected, and that it is used in conjunction with attribute 8) Hasselecttext.
SelectText () to access the value of this property
) Text property, save the text of the edit box, set this property, clear the selected, clear Undo/redo record, move the cursor to the end of the edit box, and set the modified property to False. Text is a validated that is not validated when SetText text is used. The text is truncated to the length of the maxlength. The text access value, SetText sets its value.
This property causes the TextChanged (QString text) signal to be emitted, indicating that the text has been changed.
To sum up, the Qlineedit property is mainly embodied in several aspects, on the one hand is qlineedit content display, using the alignment mode Qalignment, followed by the use of its content and display, set its echomode. The third aspect is to set the validator validate or InputMask, using the Acceptableinput table is the legal input. Then there is the action on the edit box, one is the selected text, the Hasselecttext, and the SelectText represents the selected character, text and displaytext represent the text content and the display of the different representations. Redoavailable and undoavailable indicate their operation. Whether you can select and Drap crawl drag, use dragenabled to indicate whether to activate. and whether the edit box is read-only, implements whether the framework uses readonly and frame.
2. Important Slots:
1) Clear () clears the contents of the edit box
2) copy () copies the selected text to the Clipboard, the mode must be normal
3) Cut () copy the selected text to the Clipboard clipboard and delete. If the current validator validator does not allow the deletion of the selected text, it is copied only and not deleted.
4) paste () inserts the Clipboard text into the cursor position, removes any selections, and Lineedit cannot be read-only read-only. If the final result does not conform to the current validator, it will not be processed.
5) Redo (), reset execution last executed, redo must be available, that is, prior to having undo operation
6) Undo (), undo the last step performed, Undoavailable is executable, deselect releases all selections, and sets the start position of the selection to the current cursor position
6) SelectAll (), select all the text and move the cursor to the end of the text. One of the biggest uses is to use a default value, and when the mouse clicks, all selected selected text will be deleted.
7) SetText (QString text), set the corresponding text content. The same attribute text is introduced.
3. Important Signals
1) cursorpositionchange (int old,int new); Whenever the cursor moves, the position is set to old, the new position is set to new, you can use the setcursorposition (int) setting, and Cursorposition () to get the current position.
2) editingfinished (): When the return key is pressed or the edit box loses focus, it is important to note that if there is a validator or inputmask is set, the signal is only set to launch after satisfying this check.
3) returnpressed () This signal is pressed at returnkey or Enterkey. It is also necessary to satisfy the validator.
4) SelectionChanged () when the content of the selection changes, can be judged by Hasselecttext (), SelectText get the selected text content.
5) textChanged (const QString &text) This signal is reflected when the text changes, and the parameter text is the new text that is adapted.
6) textedited (const QString &text) is emitted when the text is edited. The text parameter is the corresponding subsequent text content. Unlike TextChanged, whose program changes the text will not be emitted, such as settext, but TextChanged will launch
4. Other important operation functions:
1) Constructor:
Qlineedit::qlineedit (const QString & Contents, Qwidget * parent = 0)
Create an edit box with a right content value of contents
The cursor is set to the end, and the maximum character maxlength is set to 32,767 characters.
2) Delete edit box contents operation:
Clear () empty content, backspace () If there is no text selected, remove the icon to the left of the cursor and move the cursor forward, if selected, the selected string will be deleted and the cursor will be moved to the position of the first character.
Del () to delete one character to the right of the cursor.
3) Cursor Movement
Cursorbackward (bool Mark,int Steps=1): Moves the cursor backwards steps characters, and if Mark is true, all characters that have been moved will be selected and, if False, reversed.
Cursorforward (bool Mark,int Steps=1): Moves the cursor back and forth steps characters, and if Mark is true, all characters that have been moved are selected and, if False, are reversed
Cursorwordbackward (bool mark), which moves the cursor backwards by 1 words, usually encounters a white space character, and if Mark is true it will be selected
The Cursorwordforward (bool mark) cursor moves forward 1 words, usually with a whitespace character, and if Mark is true, it is selected
End (bool mark) moves the cursor to the last position and, if Mark is true, selects the current cursor to the last position. Otherwise all the selected will be reversed.
Home (bool mark) moves the cursor to the start position. If Mark is true, the content is selected to the first position, otherwise the selected content is reversed.
4) Select or reverse the content:
Deselect () uncheck All selected text
SelectAll Select all the text
int SelectionStart () returns the index of the first position of the selected character, 1 is not selected.
setselection (int start,int length): Selects the length of the character from the specified start position, the negative number is allowed, that is, can be selected before and after.
SelectText () returns characters that have already been selected
5) Insert character inserts (QString newtext): Delete the previously selected text and insert the new text NewText, and verify that the results of the validator are not true if the value of the officer is set to the value of the new edit box Lineedit.
6) Set font bounds settextmargin (int left, int top,int right, int down)/qmargins
7) Set the validator and format mask Setvalidator or Setinputmask.
8) Context Menu execution
Qmenu *createstandartcontextmenu () creates a standard context menu that is displayed when the user clicks the right button. It is handled by the default Contextmenuevent call. Popup popup menu itself is passed to the caller.
Such as:
Qmenu *menu = Createstandardcontextmenu (); Menu->addaction (TR ("My menu Item")); ... menu->exec (Event->globalpos ()); Delete menu;
You can actually extend the menu options. As an important part of editing.
The context menu options that are named for the My menu item are displayed.
This specific how to use, follow-up will explain ContextMenu qmenu and corresponding qaction how to mix with.
In summary, qlineedit the main cursor movement of a text content operation, including the assignment of cut, replace, and check, as well as the edit box action action Undo and Redo, content deletion selection, which completes the operator cursor movement of the signal, and select the current text content of the record, as well as the context shortcut menu and so on. Its function is very powerful, and its related is that Qtextedit is multi-line Rich text editor. A detailed introduction will be made in a later section.
The Qlineedit of QT control cognition in QT introduction