Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlineedit.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QLINEEDIT_H
5#define QLINEEDIT_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qframe.h>
9#include <QtGui/qtextcursor.h>
10#include <QtCore/qstring.h>
11#include <QtCore/qmargins.h>
12
14
16
17class QValidator;
18class QMenu;
20class QCompleter;
23class QDateTimeEdit;
24class QIcon;
25class QToolButton;
26
27class Q_WIDGETS_EXPORT QLineEdit : public QWidget
28{
30
31 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask)
32 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true)
33 Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength)
34 Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
35 Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode)
36 Q_PROPERTY(QString displayText READ displayText)
37 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
39 Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
40 Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
41 Q_PROPERTY(QString selectedText READ selectedText)
42 Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
43 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
44 Q_PROPERTY(bool undoAvailable READ isUndoAvailable)
45 Q_PROPERTY(bool redoAvailable READ isRedoAvailable)
46 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput)
47 Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
48 Q_PROPERTY(Qt::CursorMoveStyle cursorMoveStyle READ cursorMoveStyle WRITE setCursorMoveStyle)
49 Q_PROPERTY(bool clearButtonEnabled READ isClearButtonEnabled WRITE setClearButtonEnabled)
50public:
53 TrailingPosition
54 };
55 Q_ENUM(ActionPosition)
56
57 explicit QLineEdit(QWidget *parent = nullptr);
58 explicit QLineEdit(const QString &, QWidget *parent = nullptr);
59 ~QLineEdit();
60
61 QString text() const;
62
63 QString displayText() const;
64
65 QString placeholderText() const;
66 void setPlaceholderText(const QString &);
67
68 int maxLength() const;
69 void setMaxLength(int);
70
71 void setFrame(bool);
72 bool hasFrame() const;
73
74 void setClearButtonEnabled(bool enable);
75 bool isClearButtonEnabled() const;
76
77 enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit };
78 Q_ENUM(EchoMode)
79 EchoMode echoMode() const;
80 void setEchoMode(EchoMode);
81
82 bool isReadOnly() const;
83 void setReadOnly(bool);
84
85#ifndef QT_NO_VALIDATOR
86 void setValidator(const QValidator *);
87 const QValidator * validator() const;
88#endif
89
90#if QT_CONFIG(completer)
92 QCompleter *completer() const;
93#endif
94
95 QSize sizeHint() const override;
96 QSize minimumSizeHint() const override;
97
98 int cursorPosition() const;
99 void setCursorPosition(int);
100 int cursorPositionAt(const QPoint &pos);
101
102 void setAlignment(Qt::Alignment flag);
103 Qt::Alignment alignment() const;
104
105 void cursorForward(bool mark, int steps = 1);
106 void cursorBackward(bool mark, int steps = 1);
107 void cursorWordForward(bool mark);
108 void cursorWordBackward(bool mark);
109 void backspace();
110 void del();
111 void home(bool mark);
112 void end(bool mark);
113
114 bool isModified() const;
115 void setModified(bool);
116
117 void setSelection(int, int);
118 bool hasSelectedText() const;
119 QString selectedText() const;
120 int selectionStart() const;
121 int selectionEnd() const;
122 int selectionLength() const;
123
124 bool isUndoAvailable() const;
125 bool isRedoAvailable() const;
126
127 void setDragEnabled(bool b);
128 bool dragEnabled() const;
129
130 void setCursorMoveStyle(Qt::CursorMoveStyle style);
131 Qt::CursorMoveStyle cursorMoveStyle() const;
132
133 QString inputMask() const;
134 void setInputMask(const QString &inputMask);
135 bool hasAcceptableInput() const;
136
137 void setTextMargins(int left, int top, int right, int bottom);
138 void setTextMargins(const QMargins &margins);
139 QMargins textMargins() const;
140
141#if QT_CONFIG(action)
142 using QWidget::addAction;
143 void addAction(QAction *action, ActionPosition position);
144 QAction *addAction(const QIcon &icon, ActionPosition position);
145#endif
146
147public Q_SLOTS:
148 void setText(const QString &);
149 void clear();
150 void selectAll();
151 void undo();
152 void redo();
153#ifndef QT_NO_CLIPBOARD
154 void cut();
155 void copy() const;
156 void paste();
157#endif
158
159public:
160 void deselect();
161 void insert(const QString &);
162#ifndef QT_NO_CONTEXTMENU
163 QMenu *createStandardContextMenu();
164#endif
165
167 void textChanged(const QString &);
168 void textEdited(const QString &);
169 void cursorPositionChanged(int, int);
174
175protected:
176 void mousePressEvent(QMouseEvent *) override;
177 void mouseMoveEvent(QMouseEvent *) override;
178 void mouseReleaseEvent(QMouseEvent *) override;
179 void mouseDoubleClickEvent(QMouseEvent *) override;
180 void keyPressEvent(QKeyEvent *) override;
181 void keyReleaseEvent(QKeyEvent *) override;
182 void focusInEvent(QFocusEvent *) override;
183 void focusOutEvent(QFocusEvent *) override;
184 void paintEvent(QPaintEvent *) override;
185#if QT_CONFIG(draganddrop)
186 void dragEnterEvent(QDragEnterEvent *) override;
187 void dragMoveEvent(QDragMoveEvent *e) override;
188 void dragLeaveEvent(QDragLeaveEvent *e) override;
189 void dropEvent(QDropEvent *) override;
190#endif
191 void changeEvent(QEvent *) override;
192#ifndef QT_NO_CONTEXTMENU
193 void contextMenuEvent(QContextMenuEvent *) override;
194#endif
195
196 void inputMethodEvent(QInputMethodEvent *) override;
197 virtual void initStyleOption(QStyleOptionFrame *option) const;
198public:
199 QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
201 void timerEvent(QTimerEvent *) override;
202 bool event(QEvent *) override;
203protected:
204 QRect cursorRect() const;
205
206public:
207
208private:
209 friend class QAbstractSpinBox;
210 friend class QAccessibleLineEdit;
211 friend class QComboBox;
212#ifdef QT_KEYPAD_NAVIGATION
213 friend class QDateTimeEdit;
214#endif
215 Q_DISABLE_COPY(QLineEdit)
216 Q_DECLARE_PRIVATE(QLineEdit)
217};
218
220
221#endif // QLINEEDIT_H
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:30
The QComboBox widget combines a button with a dropdown list.
Definition qcombobox.h:24
The QCompleter class provides completions based on an item model.
Definition qcompleter.h:24
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:594
The QDateTimeEdit class provides a widget for editing dates and times.
\inmodule QtCore
Definition qcoreevent.h:45
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:625
The QKeyEvent class describes a key event.
Definition qevent.h:424
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
void selectionChanged()
This signal is emitted whenever the selection changes.
void textEdited(const QString &)
This signal is emitted whenever the text is edited.
void returnPressed()
This signal is emitted when the Return or Enter key is used.
void cursorPositionChanged(int, int)
This signal is emitted whenever the cursor moves.
void inputRejected()
ActionPosition
This enum type describes how a line edit should display the action widgets to be added.
Definition qlineedit.h:51
@ LeadingPosition
Definition qlineedit.h:52
void textChanged(const QString &)
This signal is emitted whenever the text changes.
void editingFinished()
This signal is emitted when the Return or Enter key is used, or if the line edit loses focus and its ...
EchoMode
This enum type describes how a line edit should display its contents.
Definition qlineedit.h:77
\inmodule QtCore
Definition qmargins.h:24
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
\inmodule QtGui
Definition qevent.h:196
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\variable QStyleOptionFocusRect::backgroundColor
\inmodule QtCore
Definition qcoreevent.h:366
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition qtoolbutton.h:20
The QValidator class provides validation of input text.
Definition qvalidator.h:24
\inmodule QtCore
Definition qvariant.h:65
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
b clear()
QString text
void textChanged(const QString &newText)
cache insert(employee->id(), employee)
uint alignment
Combined button and popup list for selecting options.
Definition qcompare.h:63
InputMethodQuery
CursorMoveStyle
static jboolean cut(JNIEnv *, jobject)
static jboolean copy(JNIEnv *, jobject)
static jboolean paste(JNIEnv *, jobject)
static jboolean setSelection(JNIEnv *, jobject, jint start, jint end)
static jboolean selectAll(JNIEnv *, jobject)
GLboolean GLboolean GLboolean b
GLuint GLuint end
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLint left
GLint GLint bottom
GLboolean enable
struct _cl_event * event
GLsizei maxLength
GLuint GLenum option
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_INVOKABLE
#define Q_SLOTS
#define Q_SIGNALS
const char property[13]
Definition qwizard.cpp:101
label setAlignment(Qt::AlignLeft|Qt::AlignTop)
[0]
QFrame frame
[0]
lineEdit setCompleter(completer)
QCompleter * completer
[0]
insertRed setText("insert red text")
stack undo()
QDBusArgument argument