Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlineedit.cpp
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// Qt-Security score:significant reason:default
4
5#include "qlineedit.h"
6#include "qlineedit_p.h"
7
8#if QT_CONFIG(action)
9# include "qaction.h"
10#endif
11#include "qapplication.h"
12#include "qclipboard.h"
13#if QT_CONFIG(draganddrop)
14#include <qdrag.h>
15#endif
16#include "qdrawutil.h"
17#include "qevent.h"
18#include "qfontmetrics.h"
19#include "qstylehints.h"
20#if QT_CONFIG(menu)
21#include "qmenu.h"
22#endif
23#include "qpainter.h"
24#include "qpixmap.h"
25#include "qpointer.h"
26#include "qstringlist.h"
27#include "qstyle.h"
28#include "qstyleoption.h"
29#include "qtimer.h"
30#include "qvalidator.h"
31#include "qvariant.h"
32#include "qdebug.h"
33#if QT_CONFIG(textedit)
34#include "qtextedit.h"
35#include <private/qtextedit_p.h>
36#endif
37#include <private/qwidgettextcontrol_p.h>
38
39#if QT_CONFIG(accessibility)
40#include "qaccessible.h"
41#endif
42#if QT_CONFIG(itemviews)
43#include "qabstractitemview.h"
44#endif
45#if QT_CONFIG(style_stylesheet)
46#include "private/qstylesheetstyle_p.h"
47#endif
48#if QT_CONFIG(shortcut)
49#include "private/qapplication_p.h"
50#include "private/qshortcutmap_p.h"
51#include "qkeysequence.h"
52#define ACCEL_KEY(k) (!QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus)
53 && !QGuiApplicationPrivate::instance()->shortcutMap.hasShortcutForKeySequence(k) ?
54 u'\t' + QKeySequence(k).toString(QKeySequence::NativeText) : QString())
55#else
56#define ACCEL_KEY(k) QString()
57#endif
59#include <limits.h>
60#ifdef DrawText
61#undef DrawText
62#endif
63
65
66using namespace Qt::StringLiterals;
67
68/*!
69 Initialize \a option with the values from this QLineEdit. This method
70 is useful for subclasses when they need a QStyleOptionFrame, but don't want
71 to fill in all the information themselves.
72
73 \sa QStyleOption::initFrom()
74*/
75void QLineEdit::initStyleOption(QStyleOptionFrame *option) const
76{
77 if (!option)
78 return;
79
80 Q_D(const QLineEdit);
81 option->initFrom(this);
82 option->rect = contentsRect();
83 option->lineWidth = d->frame ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this)
84 : 0;
85 option->midLineWidth = 0;
86 option->state |= QStyle::State_Sunken;
87 if (d->control->isReadOnly())
88 option->state |= QStyle::State_ReadOnly;
89 option->features = QStyleOptionFrame::None;
90}
91
92/*!
93 \class QLineEdit
94 \brief The QLineEdit widget is a one-line text editor.
95
96 \ingroup basicwidgets
97 \inmodule QtWidgets
98
99 \image fusion-lineedit.png {Line edit showing a text greeting}
100
101 A line edit allows users to enter and edit a single line of
102 plain text with useful editing functions, including undo and redo, cut and
103 paste, and drag and drop.
104
105 By changing the echoMode() of a line edit, it can also be used as
106 a write-only field for inputs such as passwords.
107
108 QTextEdit is a related class that allows multi-line, rich text
109 editing.
110
111 \section1 Constraining Text
112
113 Use \l maxLength to define the maximum permitted length of a text. You can
114 use a \l inputMask and \l setValidator() to further constrain the text
115 content.
116
117 \section1 Editing Text
118
119 You can change the text with setText() or insert(). Use text() to retrieve
120 the text and displayText() to retrieve the displayed text (which may be
121 different, see \l{EchoMode}). You can select the text with setSelection() or
122 selectAll(), and you can cut(), copy(), and paste() the selection. To align
123 the text, use setAlignment().
124
125 When the text changes, the textChanged() signal is emitted. When the text
126 changes in some other way than by calling setText(), the textEdited() signal
127 is emitted. When the cursor is moved, the cursorPositionChanged() signal is
128 emitted. And when the Return or Enter key is selected, the returnPressed()
129 signal is emitted.
130
131 When text editing is finished, either because the line edit lost focus
132 or Return/Enter was selected, the editingFinished() signal is emitted.
133
134 If the line edit focus is lost without any text changes, the
135 editingFinished() signal won't be emitted.
136
137 If there is a validator set on the line edit, the
138 returnPressed()/editingFinished() signals will only be emitted if the
139 validator returns QValidator::Acceptable.
140
141 For more information on the many ways that QLineEdit can be used, see
142 \l {Line Edits Example}, which also provides a selection of line edit
143 examples that show the effects of various properties and validators on the
144 input and output supplied by the user.
145
146 \section1 Setting a Frame
147
148 By default, QLineEdits have a frame as specified in the platform
149 style guides. You can turn the frame off by calling setFrame(false).
150
151 \section1 Default Key Bindings
152
153 The table below describes the default key bindings.
154
155 \note The line edit also provides a context menu (usually invoked by a
156 right-click) that presents some of the editing options listed below.
157
158 \target desc
159 \table
160 \header \li Keystroke \li Action
161 \row \li Left Arrow \li Moves the cursor one character to the left.
162 \row \li Shift+Left Arrow \li Moves and selects text one character to the left.
163 \row \li Right Arrow \li Moves the cursor one character to the right.
164 \row \li Shift+Right Arrow \li Moves and selects text one character to the right.
165 \row \li Home \li Moves the cursor to the beginning of the line.
166 \row \li End \li Moves the cursor to the end of the line.
167 \row \li Backspace \li Deletes the character to the left of the cursor.
168 \row \li Ctrl+Backspace \li Deletes the word to the left of the cursor.
169 \row \li Delete \li Deletes the character to the right of the cursor.
170 \row \li Ctrl+Delete \li Deletes the word to the right of the cursor.
171 \row \li Ctrl+A \li Selects all.
172 \row \li Ctrl+C \li Copies the selected text to the clipboard.
173 \row \li Ctrl+Insert \li Copies the selected text to the clipboard.
174 \row \li Ctrl+K \li Deletes to the end of the line.
175 \row \li Ctrl+V \li Pastes the clipboard text into line edit.
176 \row \li Shift+Insert \li Pastes the clipboard text into line edit.
177 \row \li Ctrl+X \li Deletes the selected text and copies it to the clipboard.
178 \row \li Shift+Delete \li Deletes the selected text and copies it to the clipboard.
179 \row \li Ctrl+Z \li Undoes the last operation.
180 \row \li Ctrl+Y \li Redoes the last undone operation.
181 \endtable
182
183 Any other keystroke that represents a valid character, will cause the
184 character to be inserted into the line edit.
185
186 \sa QTextEdit, QLabel, QComboBox, {Line Edits Example}
187*/
188
189
190/*!
191 \fn void QLineEdit::textChanged(const QString &text)
192
193 This signal is emitted whenever the text changes. The \a text
194 argument is the new text.
195
196 Unlike textEdited(), this signal is also emitted when the text is
197 changed programmatically, for example, by calling setText().
198*/
199
200/*!
201 \fn void QLineEdit::textEdited(const QString &text)
202
203 This signal is emitted whenever the text is edited. The \a text
204 argument is the new text.
205
206 Unlike textChanged(), this signal is not emitted when the text is
207 changed programmatically, for example, by calling setText().
208*/
209
210/*!
211 \fn void QLineEdit::cursorPositionChanged(int oldPos, int newPos)
212
213 This signal is emitted whenever the cursor moves. The previous
214 position is given by \a oldPos, and the new position by \a newPos.
215
216 \sa setCursorPosition(), cursorPosition()
217*/
218
219/*!
220 \fn void QLineEdit::selectionChanged()
221
222 This signal is emitted whenever the selection changes.
223
224 \sa hasSelectedText(), selectedText()
225*/
226
227/*!
228 Constructs a line edit with no text.
229
230 The maximum text length is set to 32767 characters.
231
232 The \a parent argument is sent to the QWidget constructor.
233
234 \sa setText(), setMaxLength()
235*/
236QLineEdit::QLineEdit(QWidget* parent)
237 : QLineEdit(QString(), parent)
238{
239}
240
241/*!
242 Constructs a line edit containing the text \a contents as a child of
243 \a parent.
244
245 The cursor position is set to the end of the line and the maximum text
246 length to 32767 characters.
247
248 \sa text(), setMaxLength()
249*/
250QLineEdit::QLineEdit(const QString& contents, QWidget* parent)
251 : QWidget(*new QLineEditPrivate, parent, { })
252{
253 Q_D(QLineEdit);
254 d->init(contents);
255}
256
257
258
259/*!
260 Destroys the line edit.
261*/
262
263QLineEdit::~QLineEdit()
264{
265}
266
267
268/*!
269 \property QLineEdit::text
270 \brief The line edit's text.
271
272 Setting this property clears the selection, clears the undo/redo
273 history, moves the cursor to the end of the line, and resets the
274 \l modified property to false. The text is not validated when
275 inserted with setText().
276
277 The text is truncated to maxLength() length.
278
279 By default, this property contains an empty string.
280
281 \sa insert(), clear()
282*/
283QString QLineEdit::text() const
284{
285 Q_D(const QLineEdit);
286 return d->control->text();
287}
288
289void QLineEdit::setText(const QString& text)
290{
291 Q_D(QLineEdit);
292 d->setText(text);
293}
294
295/*!
296 \since 4.7
297
298 \property QLineEdit::placeholderText
299 \brief The line edit's placeholder text.
300
301 Setting this property makes the line edit display a grayed-out
302 placeholder text as long as the line edit is empty.
303
304 Normally, an empty line edit shows the placeholder text even
305 when it has focus. However, if the content is horizontally
306 centered, the placeholder text is not displayed under
307 the cursor when the line edit has focus.
308
309 By default, this property contains an empty string.
310
311 \sa text()
312*/
313QString QLineEdit::placeholderText() const
314{
315 Q_D(const QLineEdit);
316 return d->placeholderText;
317}
318
319void QLineEdit::setPlaceholderText(const QString& placeholderText)
320{
321 Q_D(QLineEdit);
322 if (d->placeholderText != placeholderText) {
323 d->placeholderText = placeholderText;
324 if (d->shouldShowPlaceholderText())
325 update();
326 }
327}
328
329/*!
330 \property QLineEdit::displayText
331 \brief The displayed text.
332
333 If \l echoMode is \l Normal, this returns the same as text(). If
334 \l EchoMode is \l Password or \l PasswordEchoOnEdit, it returns a string of
335 platform-dependent password mask characters (e.g. "******"). If \l EchoMode
336 is \l NoEcho, it returns an empty string.
337
338 By default, this property contains an empty string.
339
340 \sa setEchoMode(), text(), EchoMode
341*/
342
343QString QLineEdit::displayText() const
344{
345 Q_D(const QLineEdit);
346 return d->control->displayText();
347}
348
349
350/*!
351 \property QLineEdit::maxLength
352 \brief The maximum permitted length of the text.
353
354 If the text is too long, it is truncated at the limit.
355
356 If truncation occurs, any selected text will be unselected, the
357 cursor position is set to 0, and the first part of the string is
358 shown.
359
360 If the line edit has an input mask, the mask defines the maximum
361 string length.
362
363 By default, this property contains a value of 32767.
364
365 \sa inputMask
366*/
367
368int QLineEdit::maxLength() const
369{
370 Q_D(const QLineEdit);
371 return d->control->maxLength();
372}
373
374void QLineEdit::setMaxLength(int maxLength)
375{
376 Q_D(QLineEdit);
377 d->control->setMaxLength(maxLength);
378}
379
380/*!
381 \property QLineEdit::frame
382 \brief Whether the line edit draws itself with a frame.
383
384 If enabled (the default), the line edit draws itself inside a
385 frame. Otherwise, the line edit draws itself without any frame.
386*/
387bool QLineEdit::hasFrame() const
388{
389 Q_D(const QLineEdit);
390 return d->frame;
391}
392
393/*!
394 \enum QLineEdit::ActionPosition
395
396 This enum type describes how a line edit should display the action widgets to be
397 added.
398
399 \value LeadingPosition The widget is displayed to the left of the text
400 when using layout direction \c Qt::LeftToRight or to
401 the right when using \c Qt::RightToLeft, respectively.
402
403 \value TrailingPosition The widget is displayed to the right of the text
404 when using layout direction \c Qt::LeftToRight or to
405 the left when using \c Qt::RightToLeft, respectively.
406
407 \sa addAction(), removeAction(), QWidget::layoutDirection
408
409 \since 5.2
410*/
411
412#if QT_CONFIG(action)
413/*!
414 Adds the \a action to the list of actions at the \a position.
415
416 \since 5.2
417*/
418
419void QLineEdit::addAction(QAction *action, ActionPosition position)
420{
421 Q_D(QLineEdit);
422 QWidget::addAction(action);
423 d->addAction(action, nullptr, position);
424}
425
426/*!
427 \overload
428
429 Creates a new action with the given \a icon at the \a position.
430
431 \since 5.2
432*/
433
434QAction *QLineEdit::addAction(const QIcon &icon, ActionPosition position)
435{
436 QAction *result = new QAction(icon, QString(), this);
437 addAction(result, position);
438 return result;
439}
440#endif // QT_CONFIG(action)
441/*!
442 \property QLineEdit::clearButtonEnabled
443 \brief Whether the line edit displays a clear button when it is not empty.
444
445 If enabled, the line edit displays a trailing \uicontrol clear button when
446 it contains some text. Otherwise, the line edit does not show a
447 \uicontrol clear button (the default).
448
449 \sa addAction(), removeAction()
450 \since 5.2
451*/
452
453static const char clearButtonActionNameC[] = "_q_qlineeditclearaction";
454
455void QLineEdit::setClearButtonEnabled(bool enable)
456{
457#if QT_CONFIG(action)
458 Q_D(QLineEdit);
459 if (enable == isClearButtonEnabled())
460 return;
461 if (enable) {
462 QAction *clearAction = new QAction(d->clearButtonIcon(), QString(), this);
463 clearAction->setEnabled(!isReadOnly());
464 clearAction->setObjectName(QLatin1StringView(clearButtonActionNameC));
465
466 int flags = QLineEditPrivate::SideWidgetClearButton | QLineEditPrivate::SideWidgetFadeInWithText;
467 auto widgetAction = d->addAction(clearAction, nullptr, QLineEdit::TrailingPosition, flags);
468 widgetAction->setVisible(!text().isEmpty());
469 } else {
470 QAction *clearAction = findChild<QAction *>(QLatin1StringView(clearButtonActionNameC));
471 Q_ASSERT(clearAction);
472 d->removeAction(clearAction);
473 delete clearAction;
474 }
475#else
476 Q_UNUSED(enable);
477#endif // QT_CONFIG(action)
478}
479
480bool QLineEdit::isClearButtonEnabled() const
481{
482#if QT_CONFIG(action)
483 return findChild<QAction *>(QLatin1StringView(clearButtonActionNameC));
484#else
485 return false;
486#endif
487}
488
489void QLineEdit::setFrame(bool enable)
490{
491 Q_D(QLineEdit);
492 d->frame = enable;
493 update();
494 updateGeometry();
495}
496
497
498/*!
499 \enum QLineEdit::EchoMode
500
501 This enum type describes how a line edit should display its
502 contents.
503
504 \value Normal Display characters as they are entered. This is the
505 default.
506 \value NoEcho Do not display anything. This may be appropriate
507 for passwords where even the length of the
508 password should be kept secret.
509 \value Password Display platform-dependent password mask characters instead
510 of the characters actually entered.
511 \value PasswordEchoOnEdit Display characters only while they are entered.
512 Otherwise, display characters as with \c Password.
513
514 \sa setEchoMode(), echoMode()
515*/
516
517
518/*!
519 \property QLineEdit::echoMode
520 \brief The line edit's echo mode.
521
522 The echo mode determines how the text entered in the line edit is
523 displayed (or echoed) to the user.
524
525 The most common setting is \l Normal, in which the text entered by the
526 user is displayed verbatim. QLineEdit also supports modes that allow
527 the entered text to be suppressed or obscured: these include \l NoEcho,
528 \l Password and \l PasswordEchoOnEdit.
529
530 The widget's display and the ability to copy or drag the text is
531 affected by this setting.
532
533 By default, this property is set to \l Normal.
534
535 \sa EchoMode, displayText()
536*/
537
538QLineEdit::EchoMode QLineEdit::echoMode() const
539{
540 Q_D(const QLineEdit);
541 return (EchoMode) d->control->echoMode();
542}
543
544void QLineEdit::setEchoMode(EchoMode mode)
545{
546 Q_D(QLineEdit);
547 if (mode == (EchoMode)d->control->echoMode())
548 return;
549 Qt::InputMethodHints imHints = inputMethodHints();
550 imHints.setFlag(Qt::ImhHiddenText, mode == Password || mode == NoEcho);
551 imHints.setFlag(Qt::ImhNoAutoUppercase, mode != Normal);
552 imHints.setFlag(Qt::ImhNoPredictiveText, mode != Normal);
553 imHints.setFlag(Qt::ImhSensitiveData, mode != Normal);
554 setInputMethodHints(imHints);
555 d->control->setEchoMode(mode);
556 update();
557}
558
559
560#ifndef QT_NO_VALIDATOR
561/*!
562 Returns a pointer to the current input validator, or \nullptr if no
563 validator has been set.
564
565 \sa setValidator()
566*/
567
568const QValidator * QLineEdit::validator() const
569{
570 Q_D(const QLineEdit);
571 return d->control->validator();
572}
573
574/*!
575 Sets the validator for values of line edit to \a v.
576
577 The line edit's returnPressed() and editingFinished() signals will only
578 be emitted if \a v validates the line edit's content as \l{QValidator::}{Acceptable}.
579 The user may change the content to any \l{QValidator::}{Intermediate}
580 value during editing, but will be prevented from editing the text to a
581 value that \a v validates as \l{QValidator::}{Invalid}.
582
583 This allows you to constrain the text that will be stored when editing is
584 done while leaving users with enough freedom to edit the text from one valid
585 state to another.
586
587 To remove the current input validator, pass \c nullptr. The initial setting
588 is to have no input validator (any input is accepted up to maxLength()).
589
590 \sa validator(), hasAcceptableInput(), QIntValidator, QDoubleValidator,
591 QRegularExpressionValidator
592*/
593
594void QLineEdit::setValidator(const QValidator *v)
595{
596 Q_D(QLineEdit);
597 d->control->setValidator(v);
598}
599#endif // QT_NO_VALIDATOR
600
601#if QT_CONFIG(completer)
602/*!
603 \since 4.2
604
605 Sets this line edit to provide auto completions from the completer, \a c.
606 The completion mode is set using QCompleter::setCompletionMode().
607
608 To use a QCompleter with a QValidator or QLineEdit::inputMask, you need to
609 ensure that the model provided to QCompleter contains valid entries. You can
610 use the QSortFilterProxyModel to ensure that the QCompleter's model contains
611 only valid entries.
612
613 To remove the completer and disable auto-completion, pass a \c nullptr.
614
615 \sa QCompleter
616*/
617void QLineEdit::setCompleter(QCompleter *c)
618{
619 Q_D(QLineEdit);
620 if (c == d->control->completer())
621 return;
622 if (d->control->completer()) {
623 d->disconnectCompleter();
624 d->control->completer()->setWidget(nullptr);
625 if (d->control->completer()->parent() == this)
626 delete d->control->completer();
627 }
628 d->control->setCompleter(c);
629 if (!c)
630 return;
631 if (c->widget() == nullptr)
632 c->setWidget(this);
633 if (hasFocus())
634 d->connectCompleter();
635}
636
637/*!
638 \since 4.2
639
640 Returns the current QCompleter that provides completions.
641*/
642QCompleter *QLineEdit::completer() const
643{
644 Q_D(const QLineEdit);
645 return d->control->completer();
646}
647
648#endif // QT_CONFIG(completer)
649
650/*!
651 Returns a recommended size for the widget.
652
653 The width returned, in pixels, is usually enough for about 15 to
654 20 characters.
655*/
656
657QSize QLineEdit::sizeHint() const
658{
659 Q_D(const QLineEdit);
660 ensurePolished();
661 QFontMetrics fm(font());
662 const int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this);
663 const QMargins tm = d->effectiveTextMargins();
664 int h = qMax(fm.height(), qMax(14, iconSize - 2)) + 2 * QLineEditPrivate::verticalMargin
665 + tm.top() + tm.bottom()
666 + d->topmargin + d->bottommargin;
667 int w = fm.horizontalAdvance(u'x') * 17 + 2 * QLineEditPrivate::horizontalMargin
668 + tm.left() + tm.right()
669 + d->leftmargin + d->rightmargin; // "some"
670 QStyleOptionFrame opt;
671 initStyleOption(&opt);
672 return style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h), this);
673}
674
675
676/*!
677 Returns a minimum size for the line edit.
678
679 The width returned is usually enough for at least one character.
680*/
681
682QSize QLineEdit::minimumSizeHint() const
683{
684 Q_D(const QLineEdit);
685 ensurePolished();
686 QFontMetrics fm = fontMetrics();
687 const QMargins tm = d->effectiveTextMargins();
688 int h = fm.height() + qMax(2 * QLineEditPrivate::verticalMargin, fm.leading())
689 + tm.top() + tm.bottom()
690 + d->topmargin + d->bottommargin;
691 int w = fm.maxWidth() + 2 * QLineEditPrivate::horizontalMargin
692 + tm.left() + tm.right()
693 + d->leftmargin + d->rightmargin;
694 QStyleOptionFrame opt;
695 initStyleOption(&opt);
696 return style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h), this);
697}
698
699
700/*!
701 \property QLineEdit::cursorPosition
702 \brief The current cursor position for this line edit.
703
704 Setting the cursor position causes a repaint when appropriate.
705
706 By default, this property contains a value of 0.
707*/
708
709int QLineEdit::cursorPosition() const
710{
711 Q_D(const QLineEdit);
712 return d->control->cursorPosition();
713}
714
715void QLineEdit::setCursorPosition(int pos)
716{
717 Q_D(QLineEdit);
718 d->control->setCursorPosition(pos);
719}
720
721// ### What should this do if the point is outside of contentsRect? Currently returns 0.
722/*!
723 Returns the cursor position under the point \a pos.
724*/
725int QLineEdit::cursorPositionAt(const QPoint &pos)
726{
727 Q_D(QLineEdit);
728 return d->xToPos(pos.x());
729}
730
731
732
733/*!
734 \property QLineEdit::alignment
735 \brief The alignment of the line edit.
736
737 Both horizontal and vertical alignment is allowed here, Qt::AlignJustify
738 will map to Qt::AlignLeft.
739
740 By default, this property contains a combination of Qt::AlignLeft and Qt::AlignVCenter.
741
742 \sa Qt::Alignment
743*/
744
745Qt::Alignment QLineEdit::alignment() const
746{
747 Q_D(const QLineEdit);
748 return QFlag(d->alignment);
749}
750
751void QLineEdit::setAlignment(Qt::Alignment alignment)
752{
753 Q_D(QLineEdit);
754 d->alignment = alignment;
755 update();
756}
757
758
759/*!
760 Moves the cursor forward \a steps characters. If \a mark is true,
761 each character moved over is added to the selection. If \a mark is
762 false, the selection is cleared.
763
764 \sa cursorBackward()
765*/
766
767void QLineEdit::cursorForward(bool mark, int steps)
768{
769 Q_D(QLineEdit);
770 d->control->cursorForward(mark, steps);
771}
772
773
774/*!
775 Moves the cursor back \a steps characters. If \a mark is true, each
776 character moved over is added to the selection. If \a mark is
777 false, the selection is cleared.
778
779 \sa cursorForward()
780*/
781void QLineEdit::cursorBackward(bool mark, int steps)
782{
783 cursorForward(mark, -steps);
784}
785
786/*!
787 Moves the cursor one word forward. If \a mark is true, the word is
788 also selected.
789
790 \sa cursorWordBackward()
791*/
792void QLineEdit::cursorWordForward(bool mark)
793{
794 Q_D(QLineEdit);
795 d->control->cursorWordForward(mark);
796}
797
798/*!
799 Moves the cursor one word backward. If \a mark is true, the word
800 is also selected.
801
802 \sa cursorWordForward()
803*/
804
805void QLineEdit::cursorWordBackward(bool mark)
806{
807 Q_D(QLineEdit);
808 d->control->cursorWordBackward(mark);
809}
810
811
812/*!
813 If no text is selected, deletes the character to the left of the
814 text cursor, and moves the cursor one position to the left. If any
815 text is selected, the cursor is moved to the beginning of the
816 selected text, and the selected text is deleted.
817
818 \sa del()
819*/
820void QLineEdit::backspace()
821{
822 Q_D(QLineEdit);
823 d->control->backspace();
824}
825
826/*!
827 If no text is selected, deletes the character to the right of the
828 text cursor. If any text is selected, the cursor is moved to the
829 beginning of the selected text, and the selected text is deleted.
830
831 \sa backspace()
832*/
833
834void QLineEdit::del()
835{
836 Q_D(QLineEdit);
837 d->control->del();
838}
839
840/*!
841 Moves the text cursor to the beginning of the line unless it is
842 already there. If \a mark is true, text is selected towards the
843 first position. Otherwise, any selected text is unselected if the
844 cursor is moved.
845
846 \sa end()
847*/
848
849void QLineEdit::home(bool mark)
850{
851 Q_D(QLineEdit);
852 d->control->home(mark);
853}
854
855/*!
856 Moves the text cursor to the end of the line unless it is already
857 there. If \a mark is true, text is selected towards the last
858 position. Otherwise, any selected text is unselected if the cursor
859 is moved.
860
861 \sa home()
862*/
863
864void QLineEdit::end(bool mark)
865{
866 Q_D(QLineEdit);
867 d->control->end(mark);
868}
869
870
871/*!
872 \property QLineEdit::modified
873 \brief Whether the line edit's contents has been modified by the user.
874
875 The modified flag is never read by QLineEdit; it has a default value
876 of false and is changed to true whenever the user changes the line
877 edit's contents.
878
879 This is useful for things that need to provide a default value but
880 do not start out knowing what the default should be (for example, it
881 depends on other fields on the form). Start the line edit without
882 the best default, and when the default is known, if modified()
883 returns \c false (the user hasn't entered any text), insert the
884 default value.
885
886 Calling setText() resets the modified flag to false.
887*/
888
889bool QLineEdit::isModified() const
890{
891 Q_D(const QLineEdit);
892 return d->control->isModified();
893}
894
895void QLineEdit::setModified(bool modified)
896{
897 Q_D(QLineEdit);
898 d->control->setModified(modified);
899}
900
901/*!
902 \property QLineEdit::hasSelectedText
903 \brief Whether there is any text selected.
904
905 hasSelectedText() returns \c true if some or all of the text has been
906 selected by the user. Otherwise, it returns \c false.
907
908 By default, this property is \c false.
909
910 \sa selectedText()
911*/
912
913
914bool QLineEdit::hasSelectedText() const
915{
916 Q_D(const QLineEdit);
917 return d->control->hasSelectedText();
918}
919
920/*!
921 \property QLineEdit::selectedText
922 \brief The selected text.
923
924 If there is no selected text, this property's value is
925 an empty string.
926
927 By default, this property contains an empty string.
928
929 \sa hasSelectedText()
930*/
931
932QString QLineEdit::selectedText() const
933{
934 Q_D(const QLineEdit);
935 return d->control->selectedText();
936}
937
938/*!
939 Returns the index of the first selected character in the
940 line edit (or -1 if no text is selected).
941
942 \sa selectedText()
943 \sa selectionEnd()
944 \sa selectionLength()
945*/
946
947int QLineEdit::selectionStart() const
948{
949 Q_D(const QLineEdit);
950 return d->control->selectionStart();
951}
952
953/*!
954 Returns the index of the character directly after the selection
955 in the line edit (or -1 if no text is selected).
956 \since 5.10
957
958 \sa selectedText()
959 \sa selectionStart()
960 \sa selectionLength()
961*/
962int QLineEdit::selectionEnd() const
963{
964 Q_D(const QLineEdit);
965 return d->control->selectionEnd();
966}
967
968/*!
969 Returns the length of the selection.
970 \since 5.10
971
972 \sa selectedText()
973 \sa selectionStart()
974 \sa selectionEnd()
975*/
976int QLineEdit::selectionLength() const
977{
978 return selectionEnd() - selectionStart();
979}
980
981/*!
982 Selects text from position \a start and for \a length characters.
983 Negative lengths are allowed.
984
985 \sa deselect(), selectAll(), selectedText()
986*/
987
988void QLineEdit::setSelection(int start, int length)
989{
990 Q_D(QLineEdit);
991 if (Q_UNLIKELY(start < 0 || start > (int)d->control->end())) {
992 qWarning("QLineEdit::setSelection: Invalid start position (%d)", start);
993 return;
994 }
995
996 d->control->setSelection(start, length);
997
998 if (d->control->hasSelectedText()){
999 QStyleOptionFrame opt;
1000 initStyleOption(&opt);
1001 if (!style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
1002 d->setCursorVisible(false);
1003 }
1004}
1005
1006
1007/*!
1008 \property QLineEdit::undoAvailable
1009 \brief Whether undo is available.
1010
1011 Undo becomes available once the user has modified the text in the line edit.
1012
1013 By default, this property is \c false.
1014*/
1015
1016bool QLineEdit::isUndoAvailable() const
1017{
1018 Q_D(const QLineEdit);
1019 return d->control->isUndoAvailable();
1020}
1021
1022/*!
1023 \property QLineEdit::redoAvailable
1024 \brief Whether redo is available.
1025
1026 Redo becomes available once the user has performed one or more undo operations
1027 on the text in the line edit.
1028
1029 By default, this property is \c false.
1030*/
1031
1032bool QLineEdit::isRedoAvailable() const
1033{
1034 Q_D(const QLineEdit);
1035 return d->control->isRedoAvailable();
1036}
1037
1038/*!
1039 \property QLineEdit::dragEnabled
1040 \brief Whether the line edit starts a drag if the user presses and
1041 moves the mouse on some selected text.
1042
1043 Dragging is disabled by default.
1044*/
1045
1046bool QLineEdit::dragEnabled() const
1047{
1048 Q_D(const QLineEdit);
1049 return d->dragEnabled;
1050}
1051
1052void QLineEdit::setDragEnabled(bool b)
1053{
1054 Q_D(QLineEdit);
1055 d->dragEnabled = b;
1056}
1057
1058/*!
1059 \property QLineEdit::cursorMoveStyle
1060 \brief The movement style of the cursor in this line edit.
1061 \since 4.8
1062
1063 When this property is set to Qt::VisualMoveStyle, the line edit will use a
1064 visual movement style. Using the left arrow key will always cause the
1065 cursor to move left, regardless of the text's writing direction. The same
1066 behavior applies to the right arrow key.
1067
1068 When the property is set to Qt::LogicalMoveStyle (the default), within a
1069 left-to-right (LTR) text block, using the left arrow key will increase
1070 the cursor position, whereas using the right arrow key will decrease the
1071 cursor position. If the text block is right-to-left (RTL), the opposite
1072 behavior applies.
1073*/
1074
1075Qt::CursorMoveStyle QLineEdit::cursorMoveStyle() const
1076{
1077 Q_D(const QLineEdit);
1078 return d->control->cursorMoveStyle();
1079}
1080
1081void QLineEdit::setCursorMoveStyle(Qt::CursorMoveStyle style)
1082{
1083 Q_D(QLineEdit);
1084 d->control->setCursorMoveStyle(style);
1085}
1086
1087/*!
1088 \property QLineEdit::acceptableInput
1089 \brief Whether the input satisfies the inputMask and the
1090 validator.
1091
1092 By default, this property is \c true.
1093
1094 \sa setInputMask(), setValidator()
1095*/
1096bool QLineEdit::hasAcceptableInput() const
1097{
1098 Q_D(const QLineEdit);
1099 return d->control->hasAcceptableInput();
1100}
1101
1102/*!
1103 \since 4.5
1104 Sets the margins around the text inside the frame to have the
1105 sizes \a left, \a top, \a right, and \a bottom.
1106
1107 \sa textMargins()
1108*/
1109void QLineEdit::setTextMargins(int left, int top, int right, int bottom)
1110{
1111 setTextMargins({left, top, right, bottom});
1112}
1113
1114/*!
1115 \since 4.6
1116 Sets the \a margins around the text inside the frame.
1117
1118 \sa textMargins()
1119*/
1120void QLineEdit::setTextMargins(const QMargins &margins)
1121{
1122 Q_D(QLineEdit);
1123 d->textMargins = margins;
1124 updateGeometry();
1125 update();
1126}
1127
1128/*!
1129 \since 4.6
1130 Returns the widget's text margins.
1131
1132 \sa setTextMargins()
1133*/
1134QMargins QLineEdit::textMargins() const
1135{
1136 Q_D(const QLineEdit);
1137 return d->textMargins;
1138}
1139
1140/*!
1141 \property QLineEdit::inputMask
1142 \brief The validation input mask.
1143
1144 Sets the QLineEdit's validation mask. Validators can be used
1145 instead of, or in conjunction with masks; see setValidator(). The default is
1146 an empty string, which means that no input mask is used.
1147
1148 To unset the mask and return to normal QLineEdit operation, pass an empty
1149 string.
1150
1151 The input mask is an input template string. It can contain the following
1152 elements:
1153 \table
1154 \row \li Mask Characters \li Defines the \l {QChar::} {Category} of input
1155 characters that are considered valid in this position.
1156 \row \li Meta Characters \li Various special meanings (see details below).
1157 \row \li Separators \li All other characters are regarded as immutable
1158 separators.
1159 \endtable
1160
1161 The following table shows the mask and meta characters that can be used in
1162 an input mask.
1163
1164 \table
1165 \header \li Mask Character \li Meaning
1166 \row \li \c A \li Character of the Letter category required, such as A-Z,
1167 a-z.
1168 \row \li \c a \li Character of the Letter category permitted but not
1169 required.
1170 \row \li \c N \li Character of the Letter or Number category required, such
1171 as A-Z, a-z, 0-9.
1172 \row \li \c n \li Character of the Letter or Number category permitted but
1173 not required.
1174 \row \li \c X \li Any non-blank character required.
1175 \row \li \c x \li Any non-blank character permitted but not required.
1176 \row \li \c 9 \li Character of the Number category required, such as 0-9.
1177 \row \li \c 0 \li Character of the Number category permitted but not
1178 required.
1179 \row \li \c D \li Character of the Number category and larger than zero
1180 required, such as 1-9.
1181 \row \li \c d \li Character of the Number category and larger than zero
1182 permitted but not required, such as 1-9.
1183 \row \li \c # \li Character of the Number category, or plus/minus sign
1184 permitted but not required.
1185 \row \li \c H \li Hexadecimal character required. A-F, a-f, 0-9.
1186 \row \li \c h \li Hexadecimal character permitted but not required.
1187 \row \li \c B \li Binary character required. 0-1.
1188 \row \li \c b \li Binary character permitted but not required.
1189 \header \li Meta Character \li Meaning
1190 \row \li \c > \li All following alphabetic characters are uppercased.
1191 \row \li \c < \li All following alphabetic characters are lowercased.
1192 \row \li \c ! \li Switch off case conversion.
1193 \row \li \c {;c} \li Terminates the input mask and sets the \e{blank}
1194 character to \e{c}.
1195 \row \li \c {[ ] { }} \li Reserved.
1196 \row \li \tt{\\} \li Use \tt{\\} to escape the special characters listed
1197 above to use them as separators.
1198 \endtable
1199
1200 When created or cleared, the line edit will be filled with a copy of the
1201 input mask string where the meta characters have been removed, and the mask
1202 characters have been replaced with the \e{blank} character (by default, a
1203 \c space).
1204
1205 When an input mask is set, the text() method returns a modified copy of the
1206 line edit content where all the \e{blank} characters have been removed. The
1207 unmodified content can be read using displayText().
1208
1209 The hasAcceptableInput() method returns false if the current content of the
1210 line edit does not fulfill the requirements of the input mask.
1211
1212 Examples:
1213 \table
1214 \header \li Mask \li Notes
1215 \row \li \c 000.000.000.000;_ \li IP address; blanks are \c{_}.
1216 \row \li \c HH:HH:HH:HH:HH:HH;_ \li MAC address
1217 \row \li \c 0000-00-00 \li ISO Date; blanks are \c space
1218 \row \li \c >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# \li License number;
1219 blanks are \c{#} and all (alphabetic) characters are converted to
1220 uppercase.
1221 \endtable
1222
1223 To get range control (e.g., for an IP address) use masks together
1224 with \l{setValidator()}{validators}.
1225
1226 \sa maxLength, QChar::isLetter(), QChar::isNumber(), QChar::digitValue()
1227*/
1228QString QLineEdit::inputMask() const
1229{
1230 Q_D(const QLineEdit);
1231 return d->control->inputMask();
1232}
1233
1234void QLineEdit::setInputMask(const QString &inputMask)
1235{
1236 Q_D(QLineEdit);
1237 d->control->setInputMask(inputMask);
1238}
1239
1240/*!
1241 Selects all the text (highlights it) and moves the cursor to
1242 the end.
1243
1244 \note This is useful when a default value has been inserted
1245 because if the user types before clicking on the widget, the
1246 selected text will be deleted.
1247
1248 \sa setSelection(), deselect()
1249*/
1250
1251void QLineEdit::selectAll()
1252{
1253 Q_D(QLineEdit);
1254 d->control->selectAll();
1255}
1256
1257/*!
1258 Deselects any selected text.
1259
1260 \sa setSelection(), selectAll()
1261*/
1262
1263void QLineEdit::deselect()
1264{
1265 Q_D(QLineEdit);
1266 d->control->deselect();
1267}
1268
1269
1270/*!
1271 Deletes any selected text, inserts \a newText, and validates the
1272 result. If it is valid, it sets the new text as the new contents of the line
1273 edit.
1274
1275 \sa setText(), clear()
1276*/
1277void QLineEdit::insert(const QString &newText)
1278{
1279// q->resetInputContext(); //#### FIX ME IN QT
1280 Q_D(QLineEdit);
1281 d->control->insert(newText);
1282}
1283
1284/*!
1285 Clears the contents of the line edit.
1286
1287 \sa setText(), insert()
1288*/
1289void QLineEdit::clear()
1290{
1291 Q_D(QLineEdit);
1292 d->resetInputMethod();
1293 d->control->clear();
1294}
1295
1296/*!
1297 Undoes the last operation if undo is \l{QLineEdit::undoAvailable}{available}. Deselects any current
1298 selection, and updates the selection start to the current cursor
1299 position.
1300*/
1301void QLineEdit::undo()
1302{
1303 Q_D(QLineEdit);
1304 d->resetInputMethod();
1305 d->control->undo();
1306}
1307
1308/*!
1309 Redoes the last operation if redo is \l{QLineEdit::redoAvailable}{available}.
1310*/
1311void QLineEdit::redo()
1312{
1313 Q_D(QLineEdit);
1314 d->resetInputMethod();
1315 d->control->redo();
1316}
1317
1318
1319/*!
1320 \property QLineEdit::readOnly
1321 \brief Whether the line edit is read-only.
1322
1323 In read-only mode, the user can still copy the text to the
1324 clipboard, or drag and drop the text (if echoMode() is \l Normal),
1325 but cannot edit it.
1326
1327 QLineEdit does not show a cursor in read-only mode.
1328
1329 By default, this property is \c false.
1330
1331 \sa setEnabled()
1332*/
1333
1334bool QLineEdit::isReadOnly() const
1335{
1336 Q_D(const QLineEdit);
1337 return d->control->isReadOnly();
1338}
1339
1340void QLineEdit::setReadOnly(bool enable)
1341{
1342 Q_D(QLineEdit);
1343 if (d->control->isReadOnly() != enable) {
1344 d->control->setReadOnly(enable);
1345 d->setClearButtonEnabled(!enable);
1346 setAttribute(Qt::WA_MacShowFocusRect, !enable);
1347 setAttribute(Qt::WA_InputMethodEnabled, d->shouldEnableInputMethod());
1348#ifndef QT_NO_CURSOR
1349 setCursor(enable ? Qt::ArrowCursor : Qt::IBeamCursor);
1350#endif
1351 QEvent event(QEvent::ReadOnlyChange);
1352 QCoreApplication::sendEvent(this, &event);
1353 update();
1354#if QT_CONFIG(accessibility)
1355 QAccessible::State changedState;
1356 changedState.readOnly = true;
1357 QAccessibleStateChangeEvent ev(this, changedState);
1358 QAccessible::updateAccessibility(&ev);
1359#endif
1360 }
1361}
1362
1363
1364#ifndef QT_NO_CLIPBOARD
1365/*!
1366 Copies the selected text to the clipboard and deletes it, if there
1367 is any, and if echoMode() is \l Normal.
1368
1369 If the current validator disallows deleting the selected text,
1370 cut() will copy without deleting.
1371
1372 \sa copy(), paste(), setValidator()
1373*/
1374
1375void QLineEdit::cut()
1376{
1377 if (hasSelectedText()) {
1378 copy();
1379 del();
1380 }
1381}
1382
1383
1384/*!
1385 Copies the selected text to the clipboard, if there is any, and if
1386 echoMode() is \l Normal.
1387
1388 \sa cut(), paste()
1389*/
1390
1391void QLineEdit::copy() const
1392{
1393 Q_D(const QLineEdit);
1394 d->control->copy();
1395}
1396
1397/*!
1398 Inserts the clipboard's text at the cursor position, deleting any
1399 selected text, providing the line edit is not \l{QLineEdit::readOnly}{read-only}.
1400
1401 If the end result would be invalid to the current
1402 \l{setValidator()}{validator}, nothing happens.
1403
1404 \sa copy(), cut()
1405*/
1406
1407void QLineEdit::paste()
1408{
1409 Q_D(QLineEdit);
1410 d->control->paste();
1411}
1412
1413#endif // !QT_NO_CLIPBOARD
1414
1415/*!
1416 \reimp
1417*/
1418void QLineEdit::timerEvent(QTimerEvent *e)
1419{
1420 Q_D(QLineEdit);
1421 int timerId = ((QTimerEvent*)e)->timerId();
1422 if (false) {
1423#if QT_CONFIG(draganddrop)
1424 } else if (timerId == d->dndTimer.timerId()) {
1425 d->drag();
1426#endif
1427 }
1428 else if (timerId == d->tripleClickTimer.timerId())
1429 d->tripleClickTimer.stop();
1430}
1431
1432/*! \reimp
1433*/
1434bool QLineEdit::event(QEvent * e)
1435{
1436 Q_D(QLineEdit);
1437 if (e->type() == QEvent::ContextMenu) {
1438#ifndef QT_NO_IM
1439 if (d->control->composeMode())
1440 return true;
1441#endif
1442 //d->separate();
1443 } else if (e->type() == QEvent::WindowActivate) {
1444 QTimer::singleShot(0, this, [this]() {
1445 Q_D(QLineEdit);
1446 d->handleWindowActivate();
1447 });
1448#ifndef QT_NO_SHORTCUT
1449 } else if (e->type() == QEvent::ShortcutOverride) {
1450 QKeyEvent *ke = static_cast<QKeyEvent*>(e);
1451 d->control->processShortcutOverrideEvent(ke);
1452#endif
1453 } else if (e->type() == QEvent::Show) {
1454 //In order to get the cursor blinking if QComboBox::setEditable is called when the combobox has focus
1455 if (hasFocus()) {
1456 d->control->setBlinkingCursorEnabled(true);
1457 QStyleOptionFrame opt;
1458 initStyleOption(&opt);
1459 if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty())
1460 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
1461 d->setCursorVisible(true);
1462 }
1463 } else if (e->type() == QEvent::Hide) {
1464 d->control->setBlinkingCursorEnabled(false);
1465#if QT_CONFIG(action)
1466 } else if (e->type() == QEvent::ActionRemoved) {
1467 d->removeAction(static_cast<QActionEvent *>(e)->action());
1468#endif
1469 } else if (e->type() == QEvent::Resize) {
1470 d->positionSideWidgets();
1471 } else if (e->type() == QEvent::StyleChange) {
1472 d->initMouseYThreshold();
1473 }
1474 return QWidget::event(e);
1475}
1476
1477/*! \reimp
1478*/
1479void QLineEdit::mousePressEvent(QMouseEvent* e)
1480{
1481 Q_D(QLineEdit);
1482
1483 d->mousePressPos = e->position().toPoint();
1484
1485 if (d->sendMouseEventToInputContext(e))
1486 return;
1487 if (e->button() == Qt::RightButton) {
1488 e->ignore();
1489 return;
1490 }
1491 if (d->tripleClickTimer.isActive() && (e->position().toPoint() - d->tripleClick).manhattanLength() <
1492 QApplication::startDragDistance()) {
1493 selectAll();
1494 return;
1495 }
1496 bool mark = e->modifiers() & Qt::ShiftModifier;
1497#ifdef Q_OS_ANDROID
1498 mark = mark && (d->imHints & Qt::ImhNoPredictiveText);
1499#endif // Q_OS_ANDROID
1500 int cursor = d->xToPos(e->position().toPoint().x());
1501#if QT_CONFIG(draganddrop)
1502 if (!mark && d->dragEnabled && d->control->echoMode() == Normal &&
1503 e->button() == Qt::LeftButton && d->inSelection(e->position().toPoint().x())) {
1504 if (!d->dndTimer.isActive())
1505 d->dndTimer.start(QApplication::startDragTime(), this);
1506 } else
1507#endif
1508 {
1509 d->control->moveCursor(cursor, mark);
1510 }
1511}
1512
1513/*! \reimp
1514*/
1515void QLineEdit::mouseMoveEvent(QMouseEvent * e)
1516{
1517 Q_D(QLineEdit);
1518
1519 if (e->buttons() & Qt::LeftButton) {
1520#if QT_CONFIG(draganddrop)
1521 if (d->dndTimer.isActive()) {
1522 if ((d->mousePressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance())
1523 d->drag();
1524 } else
1525#endif
1526 {
1527#ifndef Q_OS_ANDROID
1528 const bool select = true;
1529#else
1530 const bool select = (d->imHints & Qt::ImhNoPredictiveText);
1531#endif
1532#ifndef QT_NO_IM
1533 if (d->mouseYThreshold > 0 && e->position().toPoint().y() > d->mousePressPos.y() + d->mouseYThreshold) {
1534 if (layoutDirection() == Qt::RightToLeft)
1535 d->control->home(select);
1536 else
1537 d->control->end(select);
1538 } else if (d->mouseYThreshold > 0 && e->position().toPoint().y() + d->mouseYThreshold < d->mousePressPos.y()) {
1539 if (layoutDirection() == Qt::RightToLeft)
1540 d->control->end(select);
1541 else
1542 d->control->home(select);
1543 } else if (d->control->composeMode() && select) {
1544 int startPos = d->xToPos(d->mousePressPos.x());
1545 int currentPos = d->xToPos(e->position().toPoint().x());
1546 if (startPos != currentPos)
1547 d->control->setSelection(startPos, currentPos - startPos);
1548
1549 } else
1550#endif
1551 {
1552 d->control->moveCursor(d->xToPos(e->position().toPoint().x()), select);
1553 }
1554 }
1555 }
1556
1557 d->sendMouseEventToInputContext(e);
1558}
1559
1560/*! \reimp
1561*/
1562void QLineEdit::mouseReleaseEvent(QMouseEvent* e)
1563{
1564 Q_D(QLineEdit);
1565 if (d->sendMouseEventToInputContext(e))
1566 return;
1567#if QT_CONFIG(draganddrop)
1568 if (e->button() == Qt::LeftButton) {
1569 if (d->dndTimer.isActive()) {
1570 d->dndTimer.stop();
1571 deselect();
1572 return;
1573 }
1574 }
1575#endif
1576#ifndef QT_NO_CLIPBOARD
1577 if (QGuiApplication::clipboard()->supportsSelection()) {
1578 if (e->button() == Qt::LeftButton) {
1579 d->control->copy(QClipboard::Selection);
1580 } else if (!d->control->isReadOnly() && e->button() == Qt::MiddleButton) {
1581 deselect();
1582 d->control->paste(QClipboard::Selection);
1583 }
1584 }
1585#endif
1586
1587 if (!isReadOnly() && rect().contains(e->position().toPoint()))
1588 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
1589 d->clickCausedFocus = 0;
1590}
1591
1592/*! \reimp
1593*/
1594void QLineEdit::mouseDoubleClickEvent(QMouseEvent* e)
1595{
1596 Q_D(QLineEdit);
1597
1598 if (e->button() == Qt::LeftButton) {
1599 int position = d->xToPos(e->position().toPoint().x());
1600
1601 // exit composition mode
1602#ifndef QT_NO_IM
1603 if (d->control->composeMode()) {
1604 int preeditPos = d->control->cursor();
1605 int posInPreedit = position - d->control->cursor();
1606 int preeditLength = d->control->preeditAreaText().size();
1607 bool positionOnPreedit = false;
1608
1609 if (posInPreedit >= 0 && posInPreedit <= preeditLength)
1610 positionOnPreedit = true;
1611
1612 int textLength = d->control->end();
1613 d->control->commitPreedit();
1614 int sizeChange = d->control->end() - textLength;
1615
1616 if (positionOnPreedit) {
1617 if (sizeChange == 0)
1618 position = -1; // cancel selection, word disappeared
1619 else
1620 // ensure not selecting after preedit if event happened there
1621 position = qBound(preeditPos, position, preeditPos + sizeChange);
1622 } else if (position > preeditPos) {
1623 // adjust positions after former preedit by how much text changed
1624 position += (sizeChange - preeditLength);
1625 }
1626 }
1627#endif
1628
1629 if (position >= 0)
1630 d->control->selectWordAtPos(position);
1631
1632 d->tripleClickTimer.start(QApplication::doubleClickInterval(), this);
1633 d->tripleClick = e->position().toPoint();
1634 } else {
1635 d->sendMouseEventToInputContext(e);
1636 }
1637}
1638
1639/*!
1640 \fn void QLineEdit::returnPressed()
1641
1642 This signal is emitted when the Return or Enter key is used.
1643
1644 \note If there is a validator() or inputMask() set on the line
1645 edit, the returnPressed() signal will only be emitted if the input
1646 follows the inputMask() and the validator() returns
1647 QValidator::Acceptable.
1648*/
1649
1650/*!
1651 \fn void QLineEdit::editingFinished()
1652
1653 This signal is emitted when the Return or Enter key is used, or if the line
1654 edit loses focus and its contents have changed since the last time this
1655 signal was emitted.
1656
1657 \note If there is a validator() or inputMask() set on the line edit and
1658 enter/return is used, the editingFinished() signal will only be emitted
1659 if the input follows the inputMask() and the validator() returns
1660 QValidator::Acceptable.
1661*/
1662
1663/*!
1664 \fn void QLineEdit::inputRejected()
1665 \since 5.12
1666
1667 This signal is emitted when the user uses a key that is not
1668 considered to be valid input. For example, if using a key results in a
1669 validator's \l {QValidator::validate()}{validate()} call to return
1670 \l {QValidator::Invalid}{Invalid}. Another case is when trying
1671 to enter more characters beyond the maximum length of the line edit.
1672
1673 \note This signal will still be emitted when only a part of the text is
1674 accepted. For example, if there is a maximum length set and the clipboard
1675 text is longer than the maximum length when it is pasted.
1676*/
1677
1678/*!
1679 Converts the given key press \a event into a line edit action.
1680
1681 If Return or Enter is used and the current text is valid (or
1682 can be \l{QValidator::fixup()}{made valid} by the
1683 validator), the signal returnPressed() is emitted.
1684
1685 \sa {Default Key Bindings}
1686*/
1687
1688void QLineEdit::keyPressEvent(QKeyEvent *event)
1689{
1690 Q_D(QLineEdit);
1691 d->control->processKeyEvent(event);
1692 if (event->isAccepted())
1693 d->control->updateCursorBlinking();
1694}
1695
1696/*!
1697 \reimp
1698*/
1699void QLineEdit::keyReleaseEvent(QKeyEvent *e)
1700{
1701 Q_D(QLineEdit);
1702 if (!isReadOnly())
1703 d->handleSoftwareInputPanel();
1704 d->control->updateCursorBlinking();
1705 QWidget::keyReleaseEvent(e);
1706}
1707
1708/*!
1709 \since 4.4
1710
1711 Returns a rectangle that includes the line edit cursor.
1712*/
1713QRect QLineEdit::cursorRect() const
1714{
1715 Q_D(const QLineEdit);
1716 return d->cursorRect();
1717}
1718
1719/*! \reimp
1720 */
1721void QLineEdit::inputMethodEvent(QInputMethodEvent *e)
1722{
1723 Q_D(QLineEdit);
1724
1725 if (echoMode() == PasswordEchoOnEdit && !d->control->passwordEchoEditing()) {
1726 // Clear the edit and reset to normal echo mode while entering input
1727 // method data; the echo mode switches back when the edit loses focus.
1728 // ### changes a public property, resets current content.
1729 d->updatePasswordEchoEditing(true);
1730 clear();
1731 }
1732
1733 d->control->processInputMethodEvent(e);
1734
1735#if QT_CONFIG(completer)
1736 if (!e->commitString().isEmpty())
1737 d->control->complete(Qt::Key_unknown);
1738#endif
1739}
1740
1741/*!\reimp
1742*/
1743QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const
1744{
1745#ifdef Q_OS_ANDROID
1746 // QTBUG-61652
1747 if (property == Qt::ImEnterKeyType) {
1748 QWidget *next = nextInFocusChain();
1749 while (next && next != this && next->focusPolicy() == Qt::NoFocus)
1750 next = next->nextInFocusChain();
1751 if (next) {
1752 const auto nextYPos = next->mapToGlobal(QPoint(0, 0)).y();
1753 const auto currentYPos = mapToGlobal(QPoint(0, 0)).y();
1754 if (currentYPos < nextYPos)
1755 // Set EnterKey to KeyNext type only if the next widget
1756 // in the focus chain is below current QLineEdit
1757 return Qt::EnterKeyNext;
1758 }
1759 }
1760#endif
1761 return inputMethodQuery(property, QVariant());
1762}
1763
1764/*!\internal
1765*/
1766QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const
1767{
1768 Q_D(const QLineEdit);
1769 switch(property) {
1770 case Qt::ImEnabled:
1771 return isEnabled() && !isReadOnly();
1772 case Qt::ImCursorRectangle:
1773 return d->cursorRect();
1774 case Qt::ImAnchorRectangle:
1775 return d->adjustedControlRect(d->control->anchorRect());
1776 case Qt::ImFont:
1777 return font();
1778 case Qt::ImAbsolutePosition:
1779 case Qt::ImCursorPosition: {
1780 const QPointF pt = argument.toPointF();
1781 if (!pt.isNull())
1782 return QVariant(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
1783 return QVariant(d->control->cursor()); }
1784 case Qt::ImSurroundingText:
1785 return QVariant(d->control->surroundingText());
1786 case Qt::ImCurrentSelection:
1787 return QVariant(selectedText());
1788 case Qt::ImMaximumTextLength:
1789 return QVariant(maxLength());
1790 case Qt::ImAnchorPosition:
1791 if (d->control->selectionStart() == d->control->selectionEnd())
1792 return QVariant(d->control->cursor());
1793 else if (d->control->selectionStart() == d->control->cursor())
1794 return QVariant(d->control->selectionEnd());
1795 else
1796 return QVariant(d->control->selectionStart());
1797 case Qt::ImReadOnly:
1798 return isReadOnly();
1799 case Qt::ImTextBeforeCursor: {
1800 const QPointF pt = argument.toPointF();
1801 if (!pt.isNull())
1802 return d->textBeforeCursor(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
1803 else
1804 return d->textBeforeCursor(d->control->cursor()); }
1805 case Qt::ImTextAfterCursor: {
1806 const QPointF pt = argument.toPointF();
1807 if (!pt.isNull())
1808 return d->textAfterCursor(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
1809 else
1810 return d->textAfterCursor(d->control->cursor()); }
1811 default:
1812 return QWidget::inputMethodQuery(property);
1813 }
1814}
1815
1816/*!\reimp
1817*/
1818
1819void QLineEdit::focusInEvent(QFocusEvent *e)
1820{
1821 Q_D(QLineEdit);
1822 if (e->reason() == Qt::TabFocusReason ||
1823 e->reason() == Qt::BacktabFocusReason ||
1824 e->reason() == Qt::ShortcutFocusReason) {
1825 if (!d->control->inputMask().isEmpty())
1826 d->control->moveCursor(d->control->nextMaskBlank(0));
1827 else if (!d->control->hasSelectedText())
1828 selectAll();
1829 else
1830 updateMicroFocus();
1831 } else if (e->reason() == Qt::MouseFocusReason) {
1832 d->clickCausedFocus = 1;
1833 updateMicroFocus();
1834 }
1835 d->control->setBlinkingCursorEnabled(true);
1836 QStyleOptionFrame opt;
1837 initStyleOption(&opt);
1838 if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty())
1839 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
1840 d->setCursorVisible(true);
1841#if QT_CONFIG(completer)
1842 if (d->control->completer()) {
1843 d->control->completer()->setWidget(this);
1844 d->connectCompleter();
1845 }
1846#endif
1847 update();
1848}
1849
1850/*!\reimp
1851*/
1852void QLineEdit::focusOutEvent(QFocusEvent *e)
1853{
1854 Q_D(QLineEdit);
1855 if (d->control->passwordEchoEditing()) {
1856 // Reset the echomode back to PasswordEchoOnEdit when the widget loses
1857 // focus.
1858 d->updatePasswordEchoEditing(false);
1859 }
1860
1861 Qt::FocusReason reason = e->reason();
1862 if (reason != Qt::ActiveWindowFocusReason &&
1863 reason != Qt::PopupFocusReason)
1864 deselect();
1865
1866 d->setCursorVisible(false);
1867 d->control->setBlinkingCursorEnabled(false);
1868 if (reason != Qt::PopupFocusReason
1869 || !(QApplication::activePopupWidget() && QApplication::activePopupWidget()->parentWidget() == this)) {
1870 if (d->edited && (hasAcceptableInput() || d->control->fixup())) {
1871 emit editingFinished();
1872 d->edited = false;
1873 }
1874 }
1875#if QT_CONFIG(completer)
1876 if (d->control->completer())
1877 d->disconnectCompleter();
1878#endif
1879 QWidget::focusOutEvent(e);
1880}
1881
1882/*!\reimp
1883*/
1884void QLineEdit::paintEvent(QPaintEvent *)
1885{
1886 Q_D(QLineEdit);
1887 QPainter p(this);
1888 QPalette pal = palette();
1889
1890 QStyleOptionFrame panel;
1891 initStyleOption(&panel);
1892 style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
1893 QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
1894 r = r.marginsRemoved(d->effectiveTextMargins());
1895 p.setClipRect(r);
1896
1897 QFontMetrics fm = fontMetrics();
1898 int fmHeight = 0;
1899 if (d->shouldShowPlaceholderText())
1900 fmHeight = fm.boundingRect(d->placeholderText).height();
1901 else
1902 fmHeight = fm.boundingRect(d->control->text() + d->control->preeditAreaText()).height();
1903 fmHeight = qMax(fmHeight, fm.height());
1904
1905 Qt::Alignment va = QStyle::visualAlignment(d->control->layoutDirection(), QFlag(d->alignment));
1906 switch (va & Qt::AlignVertical_Mask) {
1907 case Qt::AlignBottom:
1908 d->vscroll = r.y() + r.height() - fmHeight - QLineEditPrivate::verticalMargin;
1909 break;
1910 case Qt::AlignTop:
1911 d->vscroll = r.y() + QLineEditPrivate::verticalMargin;
1912 break;
1913 default:
1914 //center
1915 d->vscroll = r.y() + (r.height() - fmHeight + 1) / 2;
1916 break;
1917 }
1918 QRect lineRect(r.x() + QLineEditPrivate::horizontalMargin, d->vscroll,
1919 r.width() - 2 * QLineEditPrivate::horizontalMargin, fmHeight);
1920
1921 if (d->shouldShowPlaceholderText()) {
1922 if (!d->placeholderText.isEmpty()) {
1923 const Qt::LayoutDirection layoutDir = d->placeholderText.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight;
1924 const Qt::Alignment alignPhText = QStyle::visualAlignment(layoutDir, QFlag(d->alignment));
1925 const QColor col = pal.placeholderText().color();
1926 QPen oldpen = p.pen();
1927 p.setPen(col);
1928 Qt::LayoutDirection oldLayoutDir = p.layoutDirection();
1929 p.setLayoutDirection(layoutDir);
1930
1931 const QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width());
1932 p.drawText(lineRect, alignPhText, elidedText);
1933 p.setPen(oldpen);
1934 p.setLayoutDirection(oldLayoutDir);
1935 }
1936 }
1937
1938 int cix = qRound(d->control->cursorToX());
1939
1940 // horizontal scrolling. d->hscroll is the left indent from the beginning
1941 // of the text line to the left edge of lineRect. we update this value
1942 // depending on the delta from the last paint event; in effect this means
1943 // the below code handles all scrolling based on the textline (widthUsed),
1944 // the line edit rect (lineRect) and the cursor position (cix).
1945 int widthUsed = qRound(d->control->naturalTextWidth()) + 1;
1946 if (widthUsed <= lineRect.width()) {
1947 // text fits in lineRect; use hscroll for alignment
1948 switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
1949 case Qt::AlignRight:
1950 d->hscroll = widthUsed - lineRect.width() + 1;
1951 break;
1952 case Qt::AlignHCenter:
1953 d->hscroll = (widthUsed - lineRect.width()) / 2;
1954 break;
1955 default:
1956 // Left
1957 d->hscroll = 0;
1958 break;
1959 }
1960 } else if (cix - d->hscroll >= lineRect.width()) {
1961 // text doesn't fit, cursor is to the right of lineRect (scroll right)
1962 d->hscroll = cix - lineRect.width() + 1;
1963 } else if (cix - d->hscroll < 0 && d->hscroll < widthUsed) {
1964 // text doesn't fit, cursor is to the left of lineRect (scroll left)
1965 d->hscroll = cix;
1966 } else if (widthUsed - d->hscroll < lineRect.width()) {
1967 // text doesn't fit, text document is to the left of lineRect; align
1968 // right
1969 d->hscroll = widthUsed - lineRect.width() + 1;
1970 } else {
1971 //in case the text is bigger than the lineedit, the hscroll can never be negative
1972 d->hscroll = qMax(0, d->hscroll);
1973 }
1974
1975 // the y offset is there to keep the baseline constant in case we have script changes in the text.
1976 // Needs to be kept in sync with QLineEditPrivate::adjustedControlRect
1977 QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent());
1978
1979 // draw text, selections and cursors
1980#if QT_CONFIG(style_stylesheet)
1981 if (QStyleSheetStyle* cssStyle = qt_styleSheet(style())) {
1982 cssStyle->styleSheetPalette(this, &panel, &pal);
1983 }
1984#endif
1985 p.setPen(pal.text().color());
1986
1987 int flags = QWidgetLineControl::DrawText;
1988
1989 if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){
1990 flags |= QWidgetLineControl::DrawSelections;
1991 // Palette only used for selections/mask and may not be in sync
1992 if (d->control->palette() != pal
1993 || d->control->palette().currentColorGroup() != pal.currentColorGroup())
1994 d->control->setPalette(pal);
1995 }
1996
1997 // Asian users see an IM selection text as cursor on candidate
1998 // selection phase of input method, so the ordinary cursor should be
1999 // invisible if we have a preedit string. another condition is when inputmask
2000 // isn't empty,we don't need draw cursor,because cursor and character overlapping
2001 // area is white.
2002 if (d->cursorVisible && !d->control->isReadOnly() && d->control->inputMask().isEmpty())
2003 flags |= QWidgetLineControl::DrawCursor;
2004
2005 d->control->setCursorWidth(style()->pixelMetric(QStyle::PM_TextCursorWidth, &panel, this));
2006 d->control->draw(&p, topLeft, r, flags);
2007
2008}
2009
2010
2011#if QT_CONFIG(draganddrop)
2012/*!\reimp
2013*/
2014void QLineEdit::dragMoveEvent(QDragMoveEvent *e)
2015{
2016 Q_D(QLineEdit);
2017 if (!d->control->isReadOnly() && e->mimeData()->hasFormat("text/plain"_L1)) {
2018 e->acceptProposedAction();
2019 d->control->moveCursor(d->xToPos(e->position().toPoint().x()), false);
2020 d->cursorVisible = true;
2021 update();
2022 }
2023}
2024
2025/*!\reimp */
2026void QLineEdit::dragEnterEvent(QDragEnterEvent * e)
2027{
2028 QLineEdit::dragMoveEvent(e);
2029}
2030
2031/*!\reimp */
2032void QLineEdit::dragLeaveEvent(QDragLeaveEvent *)
2033{
2034 Q_D(QLineEdit);
2035 if (d->cursorVisible) {
2036 d->cursorVisible = false;
2037 update();
2038 }
2039}
2040
2041/*!\reimp */
2042void QLineEdit::dropEvent(QDropEvent* e)
2043{
2044 Q_D(QLineEdit);
2045 QString str = e->mimeData()->text();
2046
2047 if (!str.isNull() && !d->control->isReadOnly()) {
2048 if (e->source() == this && e->dropAction() == Qt::CopyAction)
2049 deselect();
2050 int cursorPos = d->xToPos(e->position().toPoint().x());
2051 int selStart = cursorPos;
2052 int oldSelStart = d->control->selectionStart();
2053 int oldSelEnd = d->control->selectionEnd();
2054 d->control->moveCursor(cursorPos, false);
2055 d->cursorVisible = false;
2056 e->acceptProposedAction();
2057 insert(str);
2058 if (e->source() == this) {
2059 if (e->dropAction() == Qt::MoveAction) {
2060 if (selStart > oldSelStart && selStart <= oldSelEnd)
2061 setSelection(oldSelStart, str.size());
2062 else if (selStart > oldSelEnd)
2063 setSelection(selStart - str.size(), str.size());
2064 else
2065 setSelection(selStart, str.size());
2066 } else {
2067 setSelection(selStart, str.size());
2068 }
2069 }
2070 } else {
2071 e->ignore();
2072 update();
2073 }
2074}
2075
2076#endif // QT_CONFIG(draganddrop)
2077
2078#ifndef QT_NO_CONTEXTMENU
2079/*!
2080 Shows the standard context menu created with
2081 createStandardContextMenu().
2082
2083 If you do not want the line edit to have a context menu, you can set
2084 its \l contextMenuPolicy to Qt::NoContextMenu. To customize the context
2085 menu, reimplement this function. To extend the standard context menu,
2086 reimplement this function, call createStandardContextMenu(), and extend the
2087 menu returned.
2088
2089 \snippet code/src_gui_widgets_qlineedit.cpp 0
2090
2091 The \a event parameter is used to obtain the position where
2092 the mouse cursor was when the event was generated.
2093
2094 \sa setContextMenuPolicy()
2095*/
2096void QLineEdit::contextMenuEvent(QContextMenuEvent *event)
2097{
2098 if (QMenu *menu = createStandardContextMenu()) {
2099 menu->setAttribute(Qt::WA_DeleteOnClose);
2100 menu->popup(event->globalPos());
2101 }
2102}
2103
2104/*! Creates the standard context menu, which is shown
2105 when the user clicks on the line edit with the right mouse
2106 button. It is called from the default contextMenuEvent() handler.
2107 The popup menu's ownership is transferred to the caller.
2108*/
2109
2110QMenu *QLineEdit::createStandardContextMenu()
2111{
2112 Q_D(QLineEdit);
2113 QMenu *popup = new QMenu(this);
2114 popup->setObjectName("qt_edit_menu"_L1);
2115 QAction *action = nullptr;
2116
2117 if (!isReadOnly()) {
2118 action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo));
2119 action->setEnabled(d->control->isUndoAvailable());
2120 action->setObjectName(QStringLiteral("edit-undo"));
2121 setActionIcon(action, QStringLiteral("edit-undo"));
2122 connect(action, &QAction::triggered, this, &QLineEdit::undo);
2123
2124 action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo));
2125 action->setEnabled(d->control->isRedoAvailable());
2126 action->setObjectName(QStringLiteral("edit-redo"));
2127 setActionIcon(action, QStringLiteral("edit-redo"));
2128 connect(action, &QAction::triggered, this, &QLineEdit::redo);
2129
2130 popup->addSeparator();
2131 }
2132
2133#ifndef QT_NO_CLIPBOARD
2134 if (!isReadOnly()) {
2135 action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut));
2136 action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText()
2137 && d->control->echoMode() == QLineEdit::Normal);
2138 action->setObjectName(QStringLiteral("edit-cut"));
2139 setActionIcon(action, QStringLiteral("edit-cut"));
2140 connect(action, &QAction::triggered, this, &QLineEdit::cut);
2141 }
2142
2143 action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy));
2144 action->setEnabled(d->control->hasSelectedText()
2145 && d->control->echoMode() == QLineEdit::Normal);
2146 action->setObjectName(QStringLiteral("edit-copy"));
2147 setActionIcon(action, QStringLiteral("edit-copy"));
2148 connect(action, &QAction::triggered, this, &QLineEdit::copy);
2149
2150 if (!isReadOnly()) {
2151 action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste));
2152 action->setEnabled(!d->control->isReadOnly() && !QGuiApplication::clipboard()->text().isEmpty());
2153 action->setObjectName(QStringLiteral("edit-paste"));
2154 setActionIcon(action, QStringLiteral("edit-paste"));
2155 connect(action, &QAction::triggered, this, &QLineEdit::paste);
2156 }
2157#endif
2158
2159 if (!isReadOnly()) {
2160 action = popup->addAction(QLineEdit::tr("Delete"));
2161 action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText());
2162 action->setObjectName(QStringLiteral("edit-delete"));
2163 setActionIcon(action, QStringLiteral("edit-delete"));
2164 connect(action, &QAction::triggered,
2165 d->control, &QWidgetLineControl::_q_deleteSelected);
2166 }
2167
2168 if (!popup->isEmpty())
2169 popup->addSeparator();
2170
2171 action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll));
2172 action->setEnabled(!d->control->text().isEmpty() && !d->control->allSelected());
2173 action->setObjectName(QStringLiteral("select-all"));
2174 setActionIcon(action, QStringLiteral("edit-select-all"));
2175 d->selectAllAction = action;
2176 connect(action, &QAction::triggered, this, &QLineEdit::selectAll);
2177
2178 if (!d->control->isReadOnly() && QGuiApplication::styleHints()->useRtlExtensions()) {
2179 popup->addSeparator();
2180 QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, popup);
2181 popup->addMenu(ctrlCharacterMenu);
2182 }
2183 return popup;
2184}
2185#endif // QT_NO_CONTEXTMENU
2186
2187/*! \reimp */
2188void QLineEdit::changeEvent(QEvent *ev)
2189{
2190 Q_D(QLineEdit);
2191 switch(ev->type())
2192 {
2193 case QEvent::ActivationChange:
2194 if (!palette().isEqual(QPalette::Active, QPalette::Inactive))
2195 update();
2196 break;
2197 case QEvent::FontChange:
2198 d->control->setFont(font());
2199 break;
2200 case QEvent::StyleChange:
2201 {
2202 QStyleOptionFrame opt;
2203 initStyleOption(&opt);
2204 d->control->setPasswordCharacter(char16_t(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this)));
2205 d->control->setPasswordMaskDelay(style()->styleHint(QStyle::SH_LineEdit_PasswordMaskDelay, &opt, this));
2206 }
2207 update();
2208 break;
2209 case QEvent::LayoutDirectionChange:
2210#if QT_CONFIG(toolbutton)
2211 for (const auto &e : d->trailingSideWidgets) { // Refresh icon to show arrow in right direction.
2212 if (e.flags & QLineEditPrivate::SideWidgetClearButton)
2213 static_cast<QLineEditIconButton *>(e.widget)->setIcon(d->clearButtonIcon());
2214 }
2215#endif
2216 d->positionSideWidgets();
2217 break;
2218 default:
2219 break;
2220 }
2221 QWidget::changeEvent(ev);
2222}
2223
2224QT_END_NAMESPACE
2225
2226#include "moc_qlineedit.cpp"
Combined button and popup list for selecting options.
static const char clearButtonActionNameC[]
#define ACCEL_KEY(k)
Definition qlineedit.cpp:56