📄 qlineedit.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/widgets/qlineedit.cpp:220 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QLineEdit Class</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QLineEdit Class Reference</h1><p>The QLineEdit widget is a one-line text editor.<a href="#details">More...</a><p><tt>#include <<a href="qlineedit-h.html">qlineedit.h</a>></tt><p>Inherits <a href="qframe.html">QFrame</a>.<p><a href="qlineedit-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QLineEdit"><b>QLineEdit</b></a> ( QWidget * parent, const char * name = 0 )</div></li><li><div class=fn><a href="#QLineEdit-2"><b>QLineEdit</b></a> ( const QString & contents, QWidget * parent, const char * name = 0 )</div></li><li><div class=fn><a href="#~QLineEdit"><b>~QLineEdit</b></a> ()</div></li><li><div class=fn>QString <a href="#text"><b>text</b></a> () const</div></li><li><div class=fn>QString <a href="#displayText"><b>displayText</b></a> () const</div></li><li><div class=fn>int <a href="#maxLength"><b>maxLength</b></a> () const</div></li><li><div class=fn>bool <a href="#frame"><b>frame</b></a> () const</div></li><li><div class=fn>enum <a href="#EchoMode-enum"><b>EchoMode</b></a> { Normal, NoEcho, Password }</div></li><li><div class=fn>EchoMode <a href="#echoMode"><b>echoMode</b></a> () const</div></li><li><div class=fn>bool <a href="#isReadOnly"><b>isReadOnly</b></a> () const</div></li><li><div class=fn>const QValidator * <a href="#validator"><b>validator</b></a> () const</div></li><li><div class=fn>virtual QSize <a href="#sizeHint"><b>sizeHint</b></a> () const</div></li><li><div class=fn>virtual QSize <a href="#minimumSizeHint"><b>minimumSizeHint</b></a> () const</div></li><li><div class=fn>int <a href="#cursorPosition"><b>cursorPosition</b></a> () const</div></li><li><div class=fn>bool <a href="#validateAndSet"><b>validateAndSet</b></a> ( const QString & newText, int newPos, int newMarkAnchor, int newMarkDrag )</div></li><li><div class=fn>int <a href="#alignment"><b>alignment</b></a> () const</div></li><li><div class=fn>void cursorLeft ( bool mark, int steps = 1 ) <em>(obsolete)</em></div></li><li><div class=fn>void cursorRight ( bool mark, int steps = 1 ) <em>(obsolete)</em></div></li><li><div class=fn>void <a href="#cursorForward"><b>cursorForward</b></a> ( bool mark, int steps = 1 )</div></li><li><div class=fn>void <a href="#cursorBackward"><b>cursorBackward</b></a> ( bool mark, int steps = 1 )</div></li><li><div class=fn>void <a href="#cursorWordForward"><b>cursorWordForward</b></a> ( bool mark )</div></li><li><div class=fn>void <a href="#cursorWordBackward"><b>cursorWordBackward</b></a> ( bool mark )</div></li><li><div class=fn>void <a href="#backspace"><b>backspace</b></a> ()</div></li><li><div class=fn>void <a href="#del"><b>del</b></a> ()</div></li><li><div class=fn>void <a href="#home"><b>home</b></a> ( bool mark )</div></li><li><div class=fn>void <a href="#end"><b>end</b></a> ( bool mark )</div></li><li><div class=fn>void <a href="#setEdited"><b>setEdited</b></a> ( bool )</div></li><li><div class=fn>bool <a href="#edited"><b>edited</b></a> () const</div></li><li><div class=fn>bool <a href="#hasSelectedText"><b>hasSelectedText</b></a> () const</div></li><li><div class=fn>QString <a href="#selectedText"><b>selectedText</b></a> () const</div></li><li><div class=fn>bool <a href="#getSelection"><b>getSelection</b></a> ( int * start, int * end )</div></li><li><div class=fn>bool <a href="#isUndoAvailable"><b>isUndoAvailable</b></a> () const</div></li><li><div class=fn>bool <a href="#isRedoAvailable"><b>isRedoAvailable</b></a> () const</div></li><li><div class=fn>bool hasMarkedText () const <em>(obsolete)</em></div></li><li><div class=fn>QString markedText () const <em>(obsolete)</em></div></li><li><div class=fn>void <a href="#setPasswordChar"><b>setPasswordChar</b></a> ( QChar c )</div></li><li><div class=fn>QChar <a href="#passwordChar"><b>passwordChar</b></a> () const</div></li><li><div class=fn>bool <a href="#dragEnabled"><b>dragEnabled</b></a> () const</div></li><li><div class=fn>int <a href="#characterAt"><b>characterAt</b></a> ( int xpos, QChar * chr ) const</div></li></ul><h2>Public Slots</h2><ul><li><div class=fn>virtual void <a href="#setText"><b>setText</b></a> ( const QString & )</div></li><li><div class=fn>virtual void <a href="#selectAll"><b>selectAll</b></a> ()</div></li><li><div class=fn>virtual void <a href="#deselect"><b>deselect</b></a> ()</div></li><li><div class=fn>virtual void <a href="#clearValidator"><b>clearValidator</b></a> ()</div></li><li><div class=fn>virtual void <a href="#insert"><b>insert</b></a> ( const QString & newText )</div></li><li><div class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</div></li><li><div class=fn>virtual void <a href="#undo"><b>undo</b></a> ()</div></li><li><div class=fn>virtual void <a href="#redo"><b>redo</b></a> ()</div></li><li><div class=fn>virtual void <a href="#setMaxLength"><b>setMaxLength</b></a> ( int )</div></li><li><div class=fn>virtual void <a href="#setFrame"><b>setFrame</b></a> ( bool )</div></li><li><div class=fn>virtual void <a href="#setEchoMode"><b>setEchoMode</b></a> ( EchoMode )</div></li><li><div class=fn>virtual void <a href="#setReadOnly"><b>setReadOnly</b></a> ( bool )</div></li><li><div class=fn>virtual void <a href="#setValidator"><b>setValidator</b></a> ( const QValidator * v )</div></li><li><div class=fn>virtual void <a href="#setSelection"><b>setSelection</b></a> ( int start, int length )</div></li><li><div class=fn>virtual void <a href="#setCursorPosition"><b>setCursorPosition</b></a> ( int )</div></li><li><div class=fn>virtual void <a href="#setAlignment"><b>setAlignment</b></a> ( int flag )</div></li><li><div class=fn>virtual void <a href="#cut"><b>cut</b></a> ()</div></li><li><div class=fn>virtual void <a href="#copy"><b>copy</b></a> () const</div></li><li><div class=fn>virtual void <a href="#paste"><b>paste</b></a> ()</div></li><li><div class=fn>virtual void <a href="#setDragEnabled"><b>setDragEnabled</b></a> ( bool b )</div></li></ul><h2>Signals</h2><ul><li><div class=fn>void <a href="#textChanged"><b>textChanged</b></a> ( const QString & )</div></li><li><div class=fn>void <a href="#returnPressed"><b>returnPressed</b></a> ()</div></li><li><div class=fn>void <a href="#selectionChanged"><b>selectionChanged</b></a> ()</div></li></ul><h2>Properties</h2><ul><li><div class=fn>Alignment <a href="#alignment-prop"><b>alignment</b></a> - the alignment of the line edit</div></li><li><div class=fn>int <a href="#cursorPosition-prop"><b>cursorPosition</b></a> - the current cursor position for this line edit</div></li><li><div class=fn>QString <a href="#displayText-prop"><b>displayText</b></a> - the text that is displayed <em>(read only)</em></div></li><li><div class=fn>bool <a href="#dragEnabled-prop"><b>dragEnabled</b></a> - whether the lineedit starts a drag if the user presses and moves the mouse on some selected text</div></li><li><div class=fn>EchoMode <a href="#echoMode-prop"><b>echoMode</b></a> - the echo mode of the line edit</div></li><li><div class=fn>bool <a href="#edited-prop"><b>edited</b></a> - the edited flag of the line edit</div></li><li><div class=fn>bool <a href="#frame-prop"><b>frame</b></a> - whether the line edit draws itself with a frame</div></li><li><div class=fn>bool hasMarkedText - whether part of the text has been selected by the user (e.g. by clicking and dragging) <em>(read only)</em> <em>(obsolete)</em></div></li><li><div class=fn>bool <a href="#hasSelectedText-prop"><b>hasSelectedText</b></a> - whether there is any text selected <em>(read only)</em></div></li><li><div class=fn>QString markedText - the text selected by the user (e.g. by clicking and dragging), or QString::null if no text is selected <em>(read only)</em> <em>(obsolete)</em></div></li><li><div class=fn>int <a href="#maxLength-prop"><b>maxLength</b></a> - the maximum permitted length of the text in the editor</div></li><li><div class=fn>bool <a href="#readOnly-prop"><b>readOnly</b></a> - whether the line edit is read only</div></li><li><div class=fn>bool <a href="#redoAvailable-prop"><b>redoAvailable</b></a> - whether redo is available <em>(read only)</em></div></li><li><div class=fn>QString <a href="#selectedText-prop"><b>selectedText</b></a> - any text selected by the user or QString::null <em>(read only)</em></div></li><li><div class=fn>QString <a href="#text-prop"><b>text</b></a> - the text in the line</div></li><li><div class=fn>bool <a href="#undoAvailable-prop"><b>undoAvailable</b></a> - whether undo is available <em>(read only)</em></div></li></ul><h2>Protected Members</h2><ul><li><div class=fn>virtual void <a href="#keyPressEvent"><b>keyPressEvent</b></a> ( QKeyEvent * e )</div></li><li><div class=fn>void repaintArea ( int from, int to ) <em>(obsolete)</em></div></li><li><div class=fn>virtual QPopupMenu * <a href="#createPopupMenu"><b>createPopupMenu</b></a> ()</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2><p> The QLineEdit widget is a one-line text editor.<p> <p> A line edit allows the user to enter and edit a single line of plaintext with a useful collection of editing functions, including undo andredo, cut and paste, and drag and drop.<p> By changing the <a href="#echoMode">echoMode</a>() of a line edit, it can also be used as a"write-only" field, for inputs such as passwords.<p> The length of the field can be constrained to <a href="#maxLength">maxLength</a>(), or thevalue can be arbitrarily constrained by setting a <a href="#validator">validator</a>().<p> A closely related class is <a href="qtextedit.html">QTextEdit</a> which allows multi-line, rich-textediting.<p> You can change the text with <a href="#setText">setText</a>() or <a href="#insert">insert</a>(). The text isretrieved with <a href="#text">text</a>(); the displayed text (which may be different,see <a href="#EchoMode-enum">EchoMode</a>) is retrieved with <a href="#displayText">displayText</a>(). Text can beselected with <a href="#setSelection">setSelection</a>() or <a href="#selectAll">selectAll</a>(), and the selection canbe <a href="#cut">cut</a>(), <a href="#copy">copy</a>()ied and <a href="#paste">paste</a>()d. The text can be aligned with<a href="#setAlignment">setAlignment</a>().<p> When the text changes the <a href="#textChanged">textChanged</a>() signal is emitted; when theReturn or Enter key is pressed the <a href="#returnPressed">returnPressed</a>() signal isemitted.<p> By default, QLineEdits have a frame as specified by the Windows andMotif style guides; you can turn it off by calling <a href="#setFrame">setFrame</a>(FALSE).<p> The default key bindings are described below. Aright mouse button menu presents some of the editing commands tothe user.<a name="desc"></a><ul><li> <em>Left</em> Arrow - moves the cursor one character to the left.<li> <em>Right</em> Arrow - moves the cursor one character to the right.<li> <em>Backspace</em> - deletes the character to the left of the cursor.<li> <em>Home</em> - moves the cursor to the beginning of the line.<li> <em>End</em> - moves the cursor to the end of the line.<li> <em>Delete</em> - deletes the character to the right of the cursor.<li> <em>Shift+Left</em> Arrow - moves and selects text one character to the left.<li> <em>Shift+Right</em> Arrow - moves and selects text one character to the right.<li> <em>Ctrl+A</em> - moves the cursor to the beginning of the line.<li> <em>Ctrl+B</em> - moves the cursor one character to the left.<li> <em>Ctrl+C</em> - copies the selected text to the clipboard. (Windows alsosupports Ctrl+Insert for this operation.)<li> <em>Ctrl+D</em> - deletes the character to the right of the cursor.<li> <em>Ctrl+E</em> - moves the cursor to the end of the line.<li> <em>Ctrl+F</em> - moves the cursor one character to the right.<li> <em>Ctrl+H</em> - deletes the character to the left of the cursor.<li> <em>Ctrl+K</em> - deletes to the end of the line.<li> <em>Ctrl+V</em> - pastes the clipboard text into line edit. (Windows alsosupports Shift+Insert for this operation.)<li> <em>Ctrl+X</em> - deletes the selected text and copies it to the clipboard.(Windows also supports Shift+Delete for this operation.)<li> <em>Ctrl+Z</em> - undoes the last operation.<li> <em>Ctrl+Y</em> - redoes the last undone operation.</ul><p> Any other key sequence, that represents a valid character, will cause thecharacter to be inserted into the line.<p> <img src=qlined-m.png> <img src=qlined-w.png><p> <p>See also <a href="qtextedit.html">QTextEdit</a>, <a href="qlabel.html">QLabel</a>, <a href="qcombobox.html">QComboBox</a>, <a href="guibooks.html#fowler">GUI Design Handbook: Field, Entry</a> and <a href="basic.html">Basic Widgets</a>.<hr><h2>Member Type Documentation</h2><h3 class=fn><a name="EchoMode-enum"></a>QLineEdit::EchoMode</h3> <p> This enum type describes how a line edit should display itscontents. The defined values are:<ul><li><tt>QLineEdit::Normal</tt> - display characters as they are entered. This isthe default.<li><tt>QLineEdit::NoEcho</tt> - do not display anything. This may be appropriatefor passwords where even the length of the password shouldbe kept secret.<li><tt>QLineEdit::Password</tt> - display asterisks instead of the charactersactually entered.</ul><p> <p>See also <a href="#echoMode-prop">echoMode</a> and <a href="#echoMode-prop">echoMode</a>.<hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QLineEdit"></a>QLineEdit::QLineEdit ( <a href="qwidget.html">QWidget</a> * parent, const char * name = 0 )</h3>Constructs a line edit with no text.<p> The maximum text length is set to 32767 characters.<p> The <em>parent</em> and <em>name</em> arguments are sent to the <a href="qwidget.html">QWidget</a> constructor.<p> <p>See also <a href="#text-prop">text</a> and <a href="#maxLength-prop">maxLength</a>.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -