QtBase  v6.3.1
qlineedit.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QLINEEDIT_H
41 #define QLINEEDIT_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtWidgets/qframe.h>
45 #include <QtGui/qtextcursor.h>
46 #include <QtCore/qstring.h>
47 #include <QtCore/qmargins.h>
48 
50 
52 
53 class QValidator;
54 class QMenu;
55 class QLineEditPrivate;
56 class QCompleter;
57 class QStyleOptionFrame;
58 class QAbstractSpinBox;
59 class QDateTimeEdit;
60 class QIcon;
61 class QToolButton;
62 
63 class Q_WIDGETS_EXPORT QLineEdit : public QWidget
64 {
65  Q_OBJECT
66 
67  Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask)
68  Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true)
69  Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength)
70  Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
71  Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode)
72  Q_PROPERTY(QString displayText READ displayText)
73  Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
75  Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
76  Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
77  Q_PROPERTY(QString selectedText READ selectedText)
78  Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
79  Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
80  Q_PROPERTY(bool undoAvailable READ isUndoAvailable)
81  Q_PROPERTY(bool redoAvailable READ isRedoAvailable)
82  Q_PROPERTY(bool acceptableInput READ hasAcceptableInput)
83  Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
84  Q_PROPERTY(Qt::CursorMoveStyle cursorMoveStyle READ cursorMoveStyle WRITE setCursorMoveStyle)
85  Q_PROPERTY(bool clearButtonEnabled READ isClearButtonEnabled WRITE setClearButtonEnabled)
86 public:
89  TrailingPosition
90  };
91  Q_ENUM(ActionPosition)
92 
93  explicit QLineEdit(QWidget *parent = nullptr);
94  explicit QLineEdit(const QString &, QWidget *parent = nullptr);
95  ~QLineEdit();
96 
97  QString text() const;
98 
99  QString displayText() const;
100 
101  QString placeholderText() const;
102  void setPlaceholderText(const QString &);
103 
104  int maxLength() const;
105  void setMaxLength(int);
106 
107  void setFrame(bool);
108  bool hasFrame() const;
109 
110  void setClearButtonEnabled(bool enable);
111  bool isClearButtonEnabled() const;
112 
113  enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit };
114  Q_ENUM(EchoMode)
115  EchoMode echoMode() const;
116  void setEchoMode(EchoMode);
117 
118  bool isReadOnly() const;
119  void setReadOnly(bool);
120 
121 #ifndef QT_NO_VALIDATOR
122  void setValidator(const QValidator *);
123  const QValidator * validator() const;
124 #endif
125 
126 #if QT_CONFIG(completer)
128  QCompleter *completer() const;
129 #endif
130 
131  QSize sizeHint() const override;
132  QSize minimumSizeHint() const override;
133 
134  int cursorPosition() const;
135  void setCursorPosition(int);
136  int cursorPositionAt(const QPoint &pos);
137 
138  void setAlignment(Qt::Alignment flag);
139  Qt::Alignment alignment() const;
140 
141  void cursorForward(bool mark, int steps = 1);
142  void cursorBackward(bool mark, int steps = 1);
143  void cursorWordForward(bool mark);
144  void cursorWordBackward(bool mark);
145  void backspace();
146  void del();
147  void home(bool mark);
148  void end(bool mark);
149 
150  bool isModified() const;
151  void setModified(bool);
152 
153  void setSelection(int, int);
154  bool hasSelectedText() const;
155  QString selectedText() const;
156  int selectionStart() const;
157  int selectionEnd() const;
158  int selectionLength() const;
159 
160  bool isUndoAvailable() const;
161  bool isRedoAvailable() const;
162 
163  void setDragEnabled(bool b);
164  bool dragEnabled() const;
165 
166  void setCursorMoveStyle(Qt::CursorMoveStyle style);
167  Qt::CursorMoveStyle cursorMoveStyle() const;
168 
169  QString inputMask() const;
170  void setInputMask(const QString &inputMask);
171  bool hasAcceptableInput() const;
172 
173  void setTextMargins(int left, int top, int right, int bottom);
174  void setTextMargins(const QMargins &margins);
175  QMargins textMargins() const;
176 
177 #if QT_CONFIG(action)
178  using QWidget::addAction;
179  void addAction(QAction *action, ActionPosition position);
180  QAction *addAction(const QIcon &icon, ActionPosition position);
181 #endif
182 
183 public Q_SLOTS:
184  void setText(const QString &);
185  void clear();
186  void selectAll();
187  void undo();
188  void redo();
189 #ifndef QT_NO_CLIPBOARD
190  void cut();
191  void copy() const;
192  void paste();
193 #endif
194 
195 public:
196  void deselect();
197  void insert(const QString &);
198 #ifndef QT_NO_CONTEXTMENU
199  QMenu *createStandardContextMenu();
200 #endif
201 
202 Q_SIGNALS:
203  void textChanged(const QString &);
204  void textEdited(const QString &);
205  void cursorPositionChanged(int, int);
210 
211 protected:
212  void mousePressEvent(QMouseEvent *) override;
213  void mouseMoveEvent(QMouseEvent *) override;
214  void mouseReleaseEvent(QMouseEvent *) override;
215  void mouseDoubleClickEvent(QMouseEvent *) override;
216  void keyPressEvent(QKeyEvent *) override;
217  void keyReleaseEvent(QKeyEvent *) override;
218  void focusInEvent(QFocusEvent *) override;
219  void focusOutEvent(QFocusEvent *) override;
220  void paintEvent(QPaintEvent *) override;
221 #if QT_CONFIG(draganddrop)
222  void dragEnterEvent(QDragEnterEvent *) override;
223  void dragMoveEvent(QDragMoveEvent *e) override;
224  void dragLeaveEvent(QDragLeaveEvent *e) override;
225  void dropEvent(QDropEvent *) override;
226 #endif
227  void changeEvent(QEvent *) override;
228 #ifndef QT_NO_CONTEXTMENU
229  void contextMenuEvent(QContextMenuEvent *) override;
230 #endif
231 
232  void inputMethodEvent(QInputMethodEvent *) override;
233  virtual void initStyleOption(QStyleOptionFrame *option) const;
234 public:
237  void timerEvent(QTimerEvent *) override;
238  bool event(QEvent *) override;
239 protected:
240  QRect cursorRect() const;
241 
242 public:
243 
244 private:
245  friend class QAbstractSpinBox;
246  friend class QAccessibleLineEdit;
247  friend class QComboBox;
248 #ifdef QT_KEYPAD_NAVIGATION
249  friend class QDateTimeEdit;
250 #endif
252  Q_DECLARE_PRIVATE(QLineEdit)
253  Q_PRIVATE_SLOT(d_func(), void _q_handleWindowActivate())
254  Q_PRIVATE_SLOT(d_func(), void _q_textEdited(const QString &))
255  Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged(int, int))
256 #if QT_CONFIG(completer)
257  Q_PRIVATE_SLOT(d_func(), void _q_completionHighlighted(const QString &))
258 #endif
259 #ifdef QT_KEYPAD_NAVIGATION
260  Q_PRIVATE_SLOT(d_func(), void _q_editFocusChange(bool))
261 #endif
262  Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
263  Q_PRIVATE_SLOT(d_func(), void _q_updateNeeded(const QRect &))
264  Q_PRIVATE_SLOT(d_func(), void _q_textChanged(const QString &))
265  Q_PRIVATE_SLOT(d_func(), void _q_clearButtonClicked())
266  Q_PRIVATE_SLOT(d_func(), void _q_controlEditingFinished())
267 };
268 
270 
271 #endif // QLINEEDIT_H
Arabic default style
Definition: afstyles.h:94
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition: qaction.h:65
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:60
The QCompleter class provides completions based on an item model.
Definition: qcompleter.h:60
The QContextMenuEvent class contains parameters that describe a context menu event....
Definition: qevent.h:665
The QDateTimeEdit class provides a widget for editing dates and times.
Definition: qdatetimeedit.h:58
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QFocusEvent class contains event parameters for widget focus events. \inmodule QtGui.
Definition: qevent.h:520
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:56
The QInputMethodEvent class provides parameters for input method events. \inmodule QtGui.
Definition: qevent.h:696
The QKeyEvent class describes a key event.
Definition: qevent.h:471
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:64
void selectionChanged()
void textEdited(const QString &)
void returnPressed()
void cursorPositionChanged(int, int)
void inputRejected()
ActionPosition
Definition: qlineedit.h:87
@ LeadingPosition
Definition: qlineedit.h:88
void textChanged(const QString &)
void editingFinished()
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:52
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition: qmenu.h:62
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:231
virtual void timerEvent(QTimerEvent *event)
Definition: qobject.cpp:1399
The QPaintEvent class contains event parameters for paint events. \inmodule QtGui.
Definition: qevent.h:539
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:388
the background color on which the focus rectangle is being drawn
Definition: qstyleoption.h:127
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:367
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:56
The QValidator class provides validation of input text. \inmodule QtGui.
Definition: qvalidator.h:60
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
virtual void mouseMoveEvent(QMouseEvent *event)
Definition: qwidget.cpp:9362
virtual void mousePressEvent(QMouseEvent *event)
Definition: qwidget.cpp:9384
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Definition: qwidget.cpp:9431
virtual void focusInEvent(QFocusEvent *event)
Definition: qwidget.cpp:9566
virtual void mouseReleaseEvent(QMouseEvent *event)
Definition: qwidget.cpp:9409
virtual void keyReleaseEvent(QKeyEvent *event)
Definition: qwidget.cpp:9542
QSize minimumSizeHint
the recommended minimum size for the widget
Definition: qwidget.h:183
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
Definition: qwidget.cpp:9819
virtual void changeEvent(QEvent *)
Definition: qwidget.cpp:9283
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:182
virtual void inputMethodEvent(QInputMethodEvent *)
Definition: qwidget.cpp:9804
bool event(QEvent *event) override
Definition: qwidget.cpp:8772
virtual void focusOutEvent(QFocusEvent *event)
Definition: qwidget.cpp:9592
virtual void keyPressEvent(QKeyEvent *event)
Definition: qwidget.cpp:9507
virtual void paintEvent(QPaintEvent *event)
Definition: qwidget.cpp:9684
void addAction(QAction *action)
Definition: qwidget.cpp:3129
virtual void contextMenuEvent(QContextMenuEvent *event)
Definition: qwidget.cpp:9781
map insert("Paris", "France")
b clear()
void textChanged(const QString &newText)
double e
uint alignment
union Alignment_ Alignment
auto it unsigned count const
Definition: hb-iter.hh:848
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
InputMethodQuery
Definition: qnamespace.h:1380
CursorMoveStyle
Definition: qnamespace.h:1684
action
Definition: devices.py:78
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
@ text
QT_REQUIRE_CONFIG(lineedit)
GLboolean GLboolean GLboolean b
GLuint GLuint end
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLint left
GLint GLint bottom
GLboolean enable
GLsizei maxLength
Definition: qopenglext.h:4189
GLuint GLenum option
Definition: qopenglext.h:5929
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_INVOKABLE
Definition: qtmetamacros.h:112
#define Q_SLOTS
Definition: qtmetamacros.h:80
#define Q_PRIVATE_SLOT(d, signature)
Definition: qtmetamacros.h:82
#define Q_SIGNALS
Definition: qtmetamacros.h:81
const char property[13]
Definition: qwizard.cpp:136
QIcon icon
[15]
label setAlignment(Qt::AlignLeft|Qt::AlignTop)
[0]
MyClass setText
QFrame frame
[0]
lineEdit setCompleter(completer)
QCompleter * completer
[0]
stack undo()
QDBusArgument argument
@ Password
Definition: tst_qurl.cpp:3701
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent