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.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
4#include "qlineedit.h"
5#include "qlineedit_p.h"
6
7#if QT_CONFIG(action)
8# include "qaction.h"
9#endif
10#include "qapplication.h"
11#include "qclipboard.h"
12#if QT_CONFIG(draganddrop)
13#include <qdrag.h>
14#endif
15#include "qdrawutil.h"
16#include "qevent.h"
17#include "qfontmetrics.h"
18#include "qstylehints.h"
19#if QT_CONFIG(menu)
20#include "qmenu.h"
21#endif
22#include "qpainter.h"
23#include "qpixmap.h"
24#include "qpointer.h"
25#include "qstringlist.h"
26#include "qstyle.h"
27#include "qstyleoption.h"
28#include "qtimer.h"
29#include "qvalidator.h"
30#include "qvariant.h"
31#include "qdebug.h"
32#if QT_CONFIG(textedit)
33#include "qtextedit.h"
34#include <private/qtextedit_p.h>
35#endif
36#include <private/qwidgettextcontrol_p.h>
37
38#if QT_CONFIG(accessibility)
39#include "qaccessible.h"
40#endif
41#if QT_CONFIG(itemviews)
42#include "qabstractitemview.h"
43#endif
44#include "private/qstylesheetstyle_p.h"
45
46#if QT_CONFIG(shortcut)
47#include "private/qapplication_p.h"
48#include "private/qshortcutmap_p.h"
49#include "qkeysequence.h"
50#define ACCEL_KEY(k) (!QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus) \
51 && !QGuiApplicationPrivate::instance()->shortcutMap.hasShortcutForKeySequence(k) ? \
52 u'\t' + QKeySequence(k).toString(QKeySequence::NativeText) : QString())
53#else
54#define ACCEL_KEY(k) QString()
55#endif
56
57#include <limits.h>
58#ifdef DrawText
59#undef DrawText
60#endif
61
63
64using namespace Qt::StringLiterals;
65
74{
75 if (!option)
76 return;
77
78 Q_D(const QLineEdit);
79 option->initFrom(this);
80 option->rect = contentsRect();
81 option->lineWidth = d->frame ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this)
82 : 0;
83 option->midLineWidth = 0;
85 if (d->control->isReadOnly())
87#ifdef QT_KEYPAD_NAVIGATION
88 if (hasEditFocus())
89 option->state |= QStyle::State_HasEditFocus;
90#endif
92}
93
239 : QLineEdit(QString(), parent)
240{
241}
242
253 : QWidget(*new QLineEditPrivate, parent, { })
254{
255 Q_D(QLineEdit);
256 d->init(contents);
257}
258
259
260
268
269
286{
287 Q_D(const QLineEdit);
288 return d->control->text();
289}
290
292{
293 Q_D(QLineEdit);
294 d->setText(text);
295}
296
316{
317 Q_D(const QLineEdit);
318 return d->placeholderText;
319}
320
321void QLineEdit::setPlaceholderText(const QString& placeholderText)
322{
323 Q_D(QLineEdit);
324 if (d->placeholderText != placeholderText) {
325 d->placeholderText = placeholderText;
326 if (d->shouldShowPlaceholderText())
327 update();
328 }
329}
330
346{
347 Q_D(const QLineEdit);
348 return d->control->displayText();
349}
350
351
371{
372 Q_D(const QLineEdit);
373 return d->control->maxLength();
374}
375
377{
378 Q_D(QLineEdit);
379 d->control->setMaxLength(maxLength);
380}
381
390{
391 Q_D(const QLineEdit);
392 return d->frame;
393}
394
414#if QT_CONFIG(action)
421void QLineEdit::addAction(QAction *action, ActionPosition position)
422{
423 Q_D(QLineEdit);
424 QWidget::addAction(action);
425 d->addAction(action, nullptr, position);
426}
427
436QAction *QLineEdit::addAction(const QIcon &icon, ActionPosition position)
437{
438 QAction *result = new QAction(icon, QString(), this);
440 return result;
441}
442#endif // QT_CONFIG(action)
455static const char clearButtonActionNameC[] = "_q_qlineeditclearaction";
456
458{
459#if QT_CONFIG(action)
460 Q_D(QLineEdit);
462 return;
463 if (enable) {
464 QAction *clearAction = new QAction(d->clearButtonIcon(), QString(), this);
465 clearAction->setEnabled(!isReadOnly());
466 clearAction->setObjectName(QLatin1StringView(clearButtonActionNameC));
467
469 auto widgetAction = d->addAction(clearAction, nullptr, QLineEdit::TrailingPosition, flags);
470 widgetAction->setVisible(!text().isEmpty());
471 } else {
472 QAction *clearAction = findChild<QAction *>(QLatin1StringView(clearButtonActionNameC));
473 Q_ASSERT(clearAction);
474 d->removeAction(clearAction);
475 delete clearAction;
476 }
477#else
479#endif // QT_CONFIG(action)
480}
481
483{
484#if QT_CONFIG(action)
485 return findChild<QAction *>(QLatin1StringView(clearButtonActionNameC));
486#else
487 return false;
488#endif
489}
490
492{
493 Q_D(QLineEdit);
494 d->frame = enable;
495 update();
497}
498
499
541{
542 Q_D(const QLineEdit);
543 return (EchoMode) d->control->echoMode();
544}
545
547{
548 Q_D(QLineEdit);
549 if (mode == (EchoMode)d->control->echoMode())
550 return;
551 Qt::InputMethodHints imHints = inputMethodHints();
552 imHints.setFlag(Qt::ImhHiddenText, mode == Password || mode == NoEcho);
553 imHints.setFlag(Qt::ImhNoAutoUppercase, mode != Normal);
554 imHints.setFlag(Qt::ImhNoPredictiveText, mode != Normal);
555 imHints.setFlag(Qt::ImhSensitiveData, mode != Normal);
556 setInputMethodHints(imHints);
557 d->control->setEchoMode(mode);
558 update();
559}
560
561
562#ifndef QT_NO_VALIDATOR
571{
572 Q_D(const QLineEdit);
573 return d->control->validator();
574}
575
597{
598 Q_D(QLineEdit);
599 d->control->setValidator(v);
600}
601#endif // QT_NO_VALIDATOR
602
603#if QT_CONFIG(completer)
619void QLineEdit::setCompleter(QCompleter *c)
620{
621 Q_D(QLineEdit);
622 if (c == d->control->completer())
623 return;
624 if (d->control->completer()) {
625 d->disconnectCompleter();
626 d->control->completer()->setWidget(nullptr);
627 if (d->control->completer()->parent() == this)
628 delete d->control->completer();
629 }
630 d->control->setCompleter(c);
631 if (!c)
632 return;
633 if (c->widget() == nullptr)
634 c->setWidget(this);
635 if (hasFocus())
636 d->connectCompleter();
637}
638
644QCompleter *QLineEdit::completer() const
645{
646 Q_D(const QLineEdit);
647 return d->control->completer();
648}
649
650#endif // QT_CONFIG(completer)
651
660{
661 Q_D(const QLineEdit);
663 QFontMetrics fm(font());
664 const int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this);
665 const QMargins tm = d->effectiveTextMargins();
666 int h = qMax(fm.height(), qMax(14, iconSize - 2)) + 2 * QLineEditPrivate::verticalMargin
667 + tm.top() + tm.bottom()
668 + d->topmargin + d->bottommargin;
669 int w = fm.horizontalAdvance(u'x') * 17 + 2 * QLineEditPrivate::horizontalMargin
670 + tm.left() + tm.right()
671 + d->leftmargin + d->rightmargin; // "some"
674 return style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h), this);
675}
676
677
685{
686 Q_D(const QLineEdit);
689 const QMargins tm = d->effectiveTextMargins();
690 int h = fm.height() + qMax(2 * QLineEditPrivate::verticalMargin, fm.leading())
691 + tm.top() + tm.bottom()
692 + d->topmargin + d->bottommargin;
693 int w = fm.maxWidth() + 2 * QLineEditPrivate::horizontalMargin
694 + tm.left() + tm.right()
695 + d->leftmargin + d->rightmargin;
698 return style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h), this);
699}
700
701
712{
713 Q_D(const QLineEdit);
714 return d->control->cursorPosition();
715}
716
718{
719 Q_D(QLineEdit);
720 d->control->setCursorPosition(pos);
721}
722
723// ### What should this do if the point is outside of contentsRect? Currently returns 0.
728{
729 Q_D(QLineEdit);
730 return d->xToPos(pos.x());
731}
732
733
734
747Qt::Alignment QLineEdit::alignment() const
748{
749 Q_D(const QLineEdit);
750 return QFlag(d->alignment);
751}
752
754{
755 Q_D(QLineEdit);
756 d->alignment = alignment;
757 update();
758}
759
760
769void QLineEdit::cursorForward(bool mark, int steps)
770{
771 Q_D(QLineEdit);
772 d->control->cursorForward(mark, steps);
773}
774
775
783void QLineEdit::cursorBackward(bool mark, int steps)
784{
785 cursorForward(mark, -steps);
786}
787
795{
796 Q_D(QLineEdit);
797 d->control->cursorWordForward(mark);
798}
799
808{
809 Q_D(QLineEdit);
810 d->control->cursorWordBackward(mark);
811}
812
813
823{
824 Q_D(QLineEdit);
825 d->control->backspace();
826}
827
837{
838 Q_D(QLineEdit);
839 d->control->del();
840}
841
851void QLineEdit::home(bool mark)
852{
853 Q_D(QLineEdit);
854 d->control->home(mark);
855}
856
866void QLineEdit::end(bool mark)
867{
868 Q_D(QLineEdit);
869 d->control->end(mark);
870}
871
872
892{
893 Q_D(const QLineEdit);
894 return d->control->isModified();
895}
896
897void QLineEdit::setModified(bool modified)
898{
899 Q_D(QLineEdit);
900 d->control->setModified(modified);
901}
902
917{
918 Q_D(const QLineEdit);
919 return d->control->hasSelectedText();
920}
921
935{
936 Q_D(const QLineEdit);
937 return d->control->selectedText();
938}
939
950{
951 Q_D(const QLineEdit);
952 return d->control->selectionStart();
953}
954
965{
966 Q_D(const QLineEdit);
967 return d->control->selectionEnd();
968}
969
979{
980 return selectionEnd() - selectionStart();
981}
982
991{
992 Q_D(QLineEdit);
993 if (Q_UNLIKELY(start < 0 || start > (int)d->control->end())) {
994 qWarning("QLineEdit::setSelection: Invalid start position (%d)", start);
995 return;
996 }
997
998 d->control->setSelection(start, length);
999
1000 if (d->control->hasSelectedText()){
1003 if (!style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
1004 d->setCursorVisible(false);
1005 }
1006}
1007
1008
1019{
1020 Q_D(const QLineEdit);
1021 return d->control->isUndoAvailable();
1022}
1023
1035{
1036 Q_D(const QLineEdit);
1037 return d->control->isRedoAvailable();
1038}
1039
1049{
1050 Q_D(const QLineEdit);
1051 return d->dragEnabled;
1052}
1053
1055{
1056 Q_D(QLineEdit);
1057 d->dragEnabled = b;
1058}
1059
1078{
1079 Q_D(const QLineEdit);
1080 return d->control->cursorMoveStyle();
1081}
1082
1084{
1085 Q_D(QLineEdit);
1086 d->control->setCursorMoveStyle(style);
1087}
1088
1099{
1100 Q_D(const QLineEdit);
1101 return d->control->hasAcceptableInput();
1102}
1103
1112{
1114}
1115
1123{
1124 Q_D(QLineEdit);
1125 d->textMargins = margins;
1127 update();
1128}
1129
1137{
1138 Q_D(const QLineEdit);
1139 return d->textMargins;
1140}
1141
1231{
1232 Q_D(const QLineEdit);
1233 return d->control->inputMask();
1234}
1235
1236void QLineEdit::setInputMask(const QString &inputMask)
1237{
1238 Q_D(QLineEdit);
1239 d->control->setInputMask(inputMask);
1240}
1241
1254{
1255 Q_D(QLineEdit);
1256 d->control->selectAll();
1257}
1258
1266{
1267 Q_D(QLineEdit);
1268 d->control->deselect();
1269}
1270
1271
1279void QLineEdit::insert(const QString &newText)
1280{
1281// q->resetInputContext(); //#### FIX ME IN QT
1282 Q_D(QLineEdit);
1283 d->control->insert(newText);
1284}
1285
1292{
1293 Q_D(QLineEdit);
1294 d->resetInputMethod();
1295 d->control->clear();
1296}
1297
1304{
1305 Q_D(QLineEdit);
1306 d->resetInputMethod();
1307 d->control->undo();
1308}
1309
1314{
1315 Q_D(QLineEdit);
1316 d->resetInputMethod();
1317 d->control->redo();
1318}
1319
1320
1337{
1338 Q_D(const QLineEdit);
1339 return d->control->isReadOnly();
1340}
1341
1343{
1344 Q_D(QLineEdit);
1345 if (d->control->isReadOnly() != enable) {
1346 d->control->setReadOnly(enable);
1347 d->setClearButtonEnabled(!enable);
1349 setAttribute(Qt::WA_InputMethodEnabled, d->shouldEnableInputMethod());
1350#ifndef QT_NO_CURSOR
1352#endif
1355 update();
1356#if QT_CONFIG(accessibility)
1357 QAccessible::State changedState;
1358 changedState.readOnly = true;
1359 QAccessibleStateChangeEvent ev(this, changedState);
1360 QAccessible::updateAccessibility(&ev);
1361#endif
1362 }
1363}
1364
1365
1366#ifndef QT_NO_CLIPBOARD
1378{
1379 if (hasSelectedText()) {
1380 copy();
1381 del();
1382 }
1383}
1384
1385
1394{
1395 Q_D(const QLineEdit);
1396 d->control->copy();
1397}
1398
1410{
1411 Q_D(QLineEdit);
1412 d->control->paste();
1413}
1414
1415#endif // !QT_NO_CLIPBOARD
1416
1421{
1422 Q_D(QLineEdit);
1423 int timerId = ((QTimerEvent*)e)->timerId();
1424 if (false) {
1425#if QT_CONFIG(draganddrop)
1426 } else if (timerId == d->dndTimer.timerId()) {
1427 d->drag();
1428#endif
1429 }
1430 else if (timerId == d->tripleClickTimer.timerId())
1431 d->tripleClickTimer.stop();
1432}
1433
1437{
1438 Q_D(QLineEdit);
1439 if (e->type() == QEvent::ContextMenu) {
1440#ifndef QT_NO_IM
1441 if (d->control->composeMode())
1442 return true;
1443#endif
1444 //d->separate();
1445 } else if (e->type() == QEvent::WindowActivate) {
1446 QTimer::singleShot(0, this, [this]() {
1447 Q_D(QLineEdit);
1448 d->handleWindowActivate();
1449 });
1450#ifndef QT_NO_SHORTCUT
1451 } else if (e->type() == QEvent::ShortcutOverride) {
1452 QKeyEvent *ke = static_cast<QKeyEvent*>(e);
1453 d->control->processShortcutOverrideEvent(ke);
1454#endif
1455 } else if (e->type() == QEvent::Show) {
1456 //In order to get the cursor blinking if QComboBox::setEditable is called when the combobox has focus
1457 if (hasFocus()) {
1458 d->control->setBlinkingCursorEnabled(true);
1461 if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty())
1462 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
1463 d->setCursorVisible(true);
1464 }
1465 } else if (e->type() == QEvent::Hide) {
1466 d->control->setBlinkingCursorEnabled(false);
1467#if QT_CONFIG(action)
1468 } else if (e->type() == QEvent::ActionRemoved) {
1469 d->removeAction(static_cast<QActionEvent *>(e)->action());
1470#endif
1471 } else if (e->type() == QEvent::Resize) {
1472 d->positionSideWidgets();
1473 } else if (e->type() == QEvent::StyleChange) {
1474 d->initMouseYThreshold();
1475 }
1476#ifdef QT_KEYPAD_NAVIGATION
1477 if (QApplicationPrivate::keypadNavigationEnabled()) {
1478 if (e->type() == QEvent::EnterEditFocus) {
1479 end(false);
1480 d->setCursorVisible(true);
1481 d->control->setCursorBlinkEnabled(true);
1482 } else if (e->type() == QEvent::LeaveEditFocus) {
1483 d->setCursorVisible(false);
1484 d->control->setCursorBlinkEnabled(false);
1485 if (d->edited && (d->control->hasAcceptableInput()
1486 || d->control->fixup())) {
1488 d->edited = false;
1489 }
1490 }
1491 }
1492#endif
1493 return QWidget::event(e);
1494}
1495
1499{
1500 Q_D(QLineEdit);
1501
1502 d->mousePressPos = e->position().toPoint();
1503
1504 if (d->sendMouseEventToInputContext(e))
1505 return;
1506 if (e->button() == Qt::RightButton)
1507 return;
1508#ifdef QT_KEYPAD_NAVIGATION
1509 if (QApplication::QApplicationPrivate() && !hasEditFocus()) {
1510 setEditFocus(true);
1511 // Get the completion list to pop up.
1512 if (d->control->completer())
1513 d->control->completer()->complete();
1514 }
1515#endif
1516 if (d->tripleClickTimer.isActive() && (e->position().toPoint() - d->tripleClick).manhattanLength() <
1518 selectAll();
1519 return;
1520 }
1521 bool mark = e->modifiers() & Qt::ShiftModifier;
1522#ifdef Q_OS_ANDROID
1523 mark = mark && (d->imHints & Qt::ImhNoPredictiveText);
1524#endif // Q_OS_ANDROID
1525 int cursor = d->xToPos(e->position().toPoint().x());
1526#if QT_CONFIG(draganddrop)
1527 if (!mark && d->dragEnabled && d->control->echoMode() == Normal &&
1528 e->button() == Qt::LeftButton && d->inSelection(e->position().toPoint().x())) {
1529 if (!d->dndTimer.isActive())
1530 d->dndTimer.start(QApplication::startDragTime(), this);
1531 } else
1532#endif
1533 {
1534 d->control->moveCursor(cursor, mark);
1535 }
1536}
1537
1541{
1542 Q_D(QLineEdit);
1543
1544 if (e->buttons() & Qt::LeftButton) {
1545#if QT_CONFIG(draganddrop)
1546 if (d->dndTimer.isActive()) {
1547 if ((d->mousePressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance())
1548 d->drag();
1549 } else
1550#endif
1551 {
1552#ifndef Q_OS_ANDROID
1553 const bool select = true;
1554#else
1555 const bool select = (d->imHints & Qt::ImhNoPredictiveText);
1556#endif
1557#ifndef QT_NO_IM
1558 if (d->mouseYThreshold > 0 && e->position().toPoint().y() > d->mousePressPos.y() + d->mouseYThreshold) {
1560 d->control->home(select);
1561 else
1562 d->control->end(select);
1563 } else if (d->mouseYThreshold > 0 && e->position().toPoint().y() + d->mouseYThreshold < d->mousePressPos.y()) {
1565 d->control->end(select);
1566 else
1567 d->control->home(select);
1568 } else if (d->control->composeMode() && select) {
1569 int startPos = d->xToPos(d->mousePressPos.x());
1570 int currentPos = d->xToPos(e->position().toPoint().x());
1571 if (startPos != currentPos)
1572 d->control->setSelection(startPos, currentPos - startPos);
1573
1574 } else
1575#endif
1576 {
1577 d->control->moveCursor(d->xToPos(e->position().toPoint().x()), select);
1578 }
1579 }
1580 }
1581
1582 d->sendMouseEventToInputContext(e);
1583}
1584
1588{
1589 Q_D(QLineEdit);
1590 if (d->sendMouseEventToInputContext(e))
1591 return;
1592#if QT_CONFIG(draganddrop)
1593 if (e->button() == Qt::LeftButton) {
1594 if (d->dndTimer.isActive()) {
1595 d->dndTimer.stop();
1596 deselect();
1597 return;
1598 }
1599 }
1600#endif
1601#ifndef QT_NO_CLIPBOARD
1602 if (QGuiApplication::clipboard()->supportsSelection()) {
1603 if (e->button() == Qt::LeftButton) {
1604 d->control->copy(QClipboard::Selection);
1605 } else if (!d->control->isReadOnly() && e->button() == Qt::MiddleButton) {
1606 deselect();
1607 d->control->paste(QClipboard::Selection);
1608 }
1609 }
1610#endif
1611
1612 if (!isReadOnly() && rect().contains(e->position().toPoint()))
1613 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
1614 d->clickCausedFocus = 0;
1615}
1616
1620{
1621 Q_D(QLineEdit);
1622
1623 if (e->button() == Qt::LeftButton) {
1624 int position = d->xToPos(e->position().toPoint().x());
1625
1626 // exit composition mode
1627#ifndef QT_NO_IM
1628 if (d->control->composeMode()) {
1629 int preeditPos = d->control->cursor();
1630 int posInPreedit = position - d->control->cursor();
1631 int preeditLength = d->control->preeditAreaText().size();
1632 bool positionOnPreedit = false;
1633
1634 if (posInPreedit >= 0 && posInPreedit <= preeditLength)
1635 positionOnPreedit = true;
1636
1637 int textLength = d->control->end();
1638 d->control->commitPreedit();
1639 int sizeChange = d->control->end() - textLength;
1640
1641 if (positionOnPreedit) {
1642 if (sizeChange == 0)
1643 position = -1; // cancel selection, word disappeared
1644 else
1645 // ensure not selecting after preedit if event happened there
1646 position = qBound(preeditPos, position, preeditPos + sizeChange);
1647 } else if (position > preeditPos) {
1648 // adjust positions after former preedit by how much text changed
1649 position += (sizeChange - preeditLength);
1650 }
1651 }
1652#endif
1653
1654 if (position >= 0)
1655 d->control->selectWordAtPos(position);
1656
1657 d->tripleClickTimer.start(QApplication::doubleClickInterval(), this);
1658 d->tripleClick = e->position().toPoint();
1659 } else {
1660 d->sendMouseEventToInputContext(e);
1661 }
1662}
1663
1714{
1715 Q_D(QLineEdit);
1716 #ifdef QT_KEYPAD_NAVIGATION
1717 bool select = false;
1718 switch (event->key()) {
1719 case Qt::Key_Select:
1720 if (QApplicationPrivate::keypadNavigationEnabled()) {
1721 if (hasEditFocus()) {
1722 setEditFocus(false);
1723 if (d->control->completer() && d->control->completer()->popup()->isVisible())
1724 d->control->completer()->popup()->hide();
1725 select = true;
1726 }
1727 }
1728 break;
1729 case Qt::Key_Back:
1730 case Qt::Key_No:
1731 if (!QApplicationPrivate::keypadNavigationEnabled() || !hasEditFocus()) {
1732 event->ignore();
1733 return;
1734 }
1735 break;
1736 default:
1737 if (QApplicationPrivate::keypadNavigationEnabled()) {
1738 if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) {
1739 if (!event->text().isEmpty() && event->text().at(0).isPrint()
1740 && !isReadOnly())
1741 setEditFocus(true);
1742 else {
1743 event->ignore();
1744 return;
1745 }
1746 }
1747 }
1748 }
1749
1750
1751
1752 if (QApplicationPrivate::keypadNavigationEnabled() && !select && !hasEditFocus()) {
1753 setEditFocus(true);
1754 if (event->key() == Qt::Key_Select)
1755 return; // Just start. No action.
1756 }
1757#endif
1758 d->control->processKeyEvent(event);
1759 if (event->isAccepted())
1760 d->control->updateCursorBlinking();
1761}
1762
1767{
1768 Q_D(QLineEdit);
1769 if (!isReadOnly())
1770 d->handleSoftwareInputPanel();
1771 d->control->updateCursorBlinking();
1773}
1774
1781{
1782 Q_D(const QLineEdit);
1783 return d->cursorRect();
1784}
1785
1789{
1790 Q_D(QLineEdit);
1791
1792 if (echoMode() == PasswordEchoOnEdit && !d->control->passwordEchoEditing()) {
1793 // Clear the edit and reset to normal echo mode while entering input
1794 // method data; the echo mode switches back when the edit loses focus.
1795 // ### changes a public property, resets current content.
1796 d->updatePasswordEchoEditing(true);
1797 clear();
1798 }
1799
1800#ifdef QT_KEYPAD_NAVIGATION
1801 // Focus in if currently in navigation focus on the widget
1802 // Only focus in on preedits, to allow input methods to
1803 // commit text as they focus out without interfering with focus
1804 if (QApplicationPrivate::keypadNavigationEnabled()
1805 && hasFocus() && !hasEditFocus()
1806 && !e->preeditString().isEmpty())
1807 setEditFocus(true);
1808#endif
1809
1810 d->control->processInputMethodEvent(e);
1811
1812#if QT_CONFIG(completer)
1813 if (!e->commitString().isEmpty())
1814 d->control->complete(Qt::Key_unknown);
1815#endif
1816}
1817
1821{
1822#ifdef Q_OS_ANDROID
1823 // QTBUG-61652
1826 while (next && next != this && next->focusPolicy() == Qt::NoFocus)
1827 next = next->nextInFocusChain();
1828 if (next) {
1829 const auto nextYPos = next->mapToGlobal(QPoint(0, 0)).y();
1830 const auto currentYPos = mapToGlobal(QPoint(0, 0)).y();
1831 if (currentYPos < nextYPos)
1832 // Set EnterKey to KeyNext type only if the next widget
1833 // in the focus chain is below current QLineEdit
1834 return Qt::EnterKeyNext;
1835 }
1836 }
1837#endif
1839}
1840
1844{
1845 Q_D(const QLineEdit);
1846 switch(property) {
1847 case Qt::ImEnabled:
1848 return isEnabled() && !isReadOnly();
1850 return d->cursorRect();
1852 return d->adjustedControlRect(d->control->anchorRect());
1853 case Qt::ImFont:
1854 return font();
1856 case Qt::ImCursorPosition: {
1857 const QPointF pt = argument.toPointF();
1858 if (!pt.isNull())
1859 return QVariant(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
1860 return QVariant(d->control->cursor()); }
1862 return QVariant(d->control->surroundingText());
1864 return QVariant(selectedText());
1866 return QVariant(maxLength());
1868 if (d->control->selectionStart() == d->control->selectionEnd())
1869 return QVariant(d->control->cursor());
1870 else if (d->control->selectionStart() == d->control->cursor())
1871 return QVariant(d->control->selectionEnd());
1872 else
1873 return QVariant(d->control->selectionStart());
1874 case Qt::ImReadOnly:
1875 return isReadOnly();
1877 const QPointF pt = argument.toPointF();
1878 if (!pt.isNull())
1879 return d->textBeforeCursor(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
1880 else
1881 return d->textBeforeCursor(d->control->cursor()); }
1882 case Qt::ImTextAfterCursor: {
1883 const QPointF pt = argument.toPointF();
1884 if (!pt.isNull())
1885 return d->textAfterCursor(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
1886 else
1887 return d->textAfterCursor(d->control->cursor()); }
1888 default:
1890 }
1891}
1892
1897{
1898 Q_D(QLineEdit);
1899 if (e->reason() == Qt::TabFocusReason ||
1902 if (!d->control->inputMask().isEmpty())
1903 d->control->moveCursor(d->control->nextMaskBlank(0));
1904 else if (!d->control->hasSelectedText())
1905 selectAll();
1906 else
1908 } else if (e->reason() == Qt::MouseFocusReason) {
1909 d->clickCausedFocus = 1;
1911 }
1912#ifdef QT_KEYPAD_NAVIGATION
1913 if (!QApplicationPrivate::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason))) {
1914#endif
1915 d->control->setBlinkingCursorEnabled(true);
1918 if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty())
1919 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
1920 d->setCursorVisible(true);
1921#ifdef QT_KEYPAD_NAVIGATION
1922 d->control->setCancelText(d->control->text());
1923 }
1924#endif
1925#if QT_CONFIG(completer)
1926 if (d->control->completer()) {
1927 d->control->completer()->setWidget(this);
1928 d->connectCompleter();
1929 }
1930#endif
1931 update();
1932}
1933
1937{
1938 Q_D(QLineEdit);
1939 if (d->control->passwordEchoEditing()) {
1940 // Reset the echomode back to PasswordEchoOnEdit when the widget loses
1941 // focus.
1942 d->updatePasswordEchoEditing(false);
1943 }
1944
1945 Qt::FocusReason reason = e->reason();
1946 if (reason != Qt::ActiveWindowFocusReason &&
1947 reason != Qt::PopupFocusReason)
1948 deselect();
1949
1950 d->setCursorVisible(false);
1951 d->control->setBlinkingCursorEnabled(false);
1952#ifdef QT_KEYPAD_NAVIGATION
1953 // editingFinished() is already emitted on LeaveEditFocus
1954 if (!QApplicationPrivate::keypadNavigationEnabled())
1955#endif
1956 if (reason != Qt::PopupFocusReason
1958 if (d->edited && (hasAcceptableInput() || d->control->fixup())) {
1960 d->edited = false;
1961 }
1962 }
1963#ifdef QT_KEYPAD_NAVIGATION
1964 d->control->setCancelText(QString());
1965#endif
1966#if QT_CONFIG(completer)
1967 if (d->control->completer())
1968 d->disconnectCompleter();
1969#endif
1971}
1972
1976{
1977 Q_D(QLineEdit);
1978 QPainter p(this);
1979 QPalette pal = palette();
1980
1985 r = r.marginsRemoved(d->effectiveTextMargins());
1986 p.setClipRect(r);
1987
1989 int fmHeight = 0;
1990 if (d->shouldShowPlaceholderText())
1991 fmHeight = fm.boundingRect(d->placeholderText).height();
1992 else
1993 fmHeight = fm.boundingRect(d->control->text() + d->control->preeditAreaText()).height();
1994 fmHeight = qMax(fmHeight, fm.height());
1995
1996 Qt::Alignment va = QStyle::visualAlignment(d->control->layoutDirection(), QFlag(d->alignment));
1997 switch (va & Qt::AlignVertical_Mask) {
1998 case Qt::AlignBottom:
1999 d->vscroll = r.y() + r.height() - fmHeight - QLineEditPrivate::verticalMargin;
2000 break;
2001 case Qt::AlignTop:
2002 d->vscroll = r.y() + QLineEditPrivate::verticalMargin;
2003 break;
2004 default:
2005 //center
2006 d->vscroll = r.y() + (r.height() - fmHeight + 1) / 2;
2007 break;
2008 }
2009 QRect lineRect(r.x() + QLineEditPrivate::horizontalMargin, d->vscroll,
2010 r.width() - 2 * QLineEditPrivate::horizontalMargin, fmHeight);
2011
2012 if (d->shouldShowPlaceholderText()) {
2013 if (!d->placeholderText.isEmpty()) {
2014 const Qt::LayoutDirection layoutDir = d->placeholderText.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight;
2015 const Qt::Alignment alignPhText = QStyle::visualAlignment(layoutDir, QFlag(d->alignment));
2016 const QColor col = pal.placeholderText().color();
2017 QPen oldpen = p.pen();
2018 p.setPen(col);
2019 Qt::LayoutDirection oldLayoutDir = p.layoutDirection();
2020 p.setLayoutDirection(layoutDir);
2021
2022 const QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width());
2023 p.drawText(lineRect, alignPhText, elidedText);
2024 p.setPen(oldpen);
2025 p.setLayoutDirection(oldLayoutDir);
2026 }
2027 }
2028
2029 int cix = qRound(d->control->cursorToX());
2030
2031 // horizontal scrolling. d->hscroll is the left indent from the beginning
2032 // of the text line to the left edge of lineRect. we update this value
2033 // depending on the delta from the last paint event; in effect this means
2034 // the below code handles all scrolling based on the textline (widthUsed),
2035 // the line edit rect (lineRect) and the cursor position (cix).
2036 int widthUsed = qRound(d->control->naturalTextWidth()) + 1;
2037 if (widthUsed <= lineRect.width()) {
2038 // text fits in lineRect; use hscroll for alignment
2039 switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
2040 case Qt::AlignRight:
2041 d->hscroll = widthUsed - lineRect.width() + 1;
2042 break;
2043 case Qt::AlignHCenter:
2044 d->hscroll = (widthUsed - lineRect.width()) / 2;
2045 break;
2046 default:
2047 // Left
2048 d->hscroll = 0;
2049 break;
2050 }
2051 } else if (cix - d->hscroll >= lineRect.width()) {
2052 // text doesn't fit, cursor is to the right of lineRect (scroll right)
2053 d->hscroll = cix - lineRect.width() + 1;
2054 } else if (cix - d->hscroll < 0 && d->hscroll < widthUsed) {
2055 // text doesn't fit, cursor is to the left of lineRect (scroll left)
2056 d->hscroll = cix;
2057 } else if (widthUsed - d->hscroll < lineRect.width()) {
2058 // text doesn't fit, text document is to the left of lineRect; align
2059 // right
2060 d->hscroll = widthUsed - lineRect.width() + 1;
2061 } else {
2062 //in case the text is bigger than the lineedit, the hscroll can never be negative
2063 d->hscroll = qMax(0, d->hscroll);
2064 }
2065
2066 // the y offset is there to keep the baseline constant in case we have script changes in the text.
2067 // Needs to be kept in sync with QLineEditPrivate::adjustedControlRect
2068 QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent());
2069
2070 // draw text, selections and cursors
2071#ifndef QT_NO_STYLE_STYLESHEET
2072 if (QStyleSheetStyle* cssStyle = qt_styleSheet(style())) {
2073 cssStyle->styleSheetPalette(this, &panel, &pal);
2074 }
2075#endif
2076 p.setPen(pal.text().color());
2077
2079
2080#ifdef QT_KEYPAD_NAVIGATION
2081 if (!QApplicationPrivate::keypadNavigationEnabled() || hasEditFocus())
2082#endif
2083 if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){
2085 // Palette only used for selections/mask and may not be in sync
2086 if (d->control->palette() != pal
2087 || d->control->palette().currentColorGroup() != pal.currentColorGroup())
2088 d->control->setPalette(pal);
2089 }
2090
2091 // Asian users see an IM selection text as cursor on candidate
2092 // selection phase of input method, so the ordinary cursor should be
2093 // invisible if we have a preedit string. another condition is when inputmask
2094 // isn't empty,we don't need draw cursor,because cursor and character overlapping
2095 // area is white.
2096 if (d->cursorVisible && !d->control->isReadOnly() && d->control->inputMask().isEmpty())
2098
2099 d->control->setCursorWidth(style()->pixelMetric(QStyle::PM_TextCursorWidth, &panel, this));
2100 d->control->draw(&p, topLeft, r, flags);
2101
2102}
2103
2104
2105#if QT_CONFIG(draganddrop)
2108void QLineEdit::dragMoveEvent(QDragMoveEvent *e)
2109{
2110 Q_D(QLineEdit);
2111 if (!d->control->isReadOnly() && e->mimeData()->hasFormat("text/plain"_L1)) {
2112 e->acceptProposedAction();
2113 d->control->moveCursor(d->xToPos(e->position().toPoint().x()), false);
2114 d->cursorVisible = true;
2115 update();
2116 }
2117}
2118
2120void QLineEdit::dragEnterEvent(QDragEnterEvent * e)
2121{
2122 QLineEdit::dragMoveEvent(e);
2123}
2124
2126void QLineEdit::dragLeaveEvent(QDragLeaveEvent *)
2127{
2128 Q_D(QLineEdit);
2129 if (d->cursorVisible) {
2130 d->cursorVisible = false;
2131 update();
2132 }
2133}
2134
2136void QLineEdit::dropEvent(QDropEvent* e)
2137{
2138 Q_D(QLineEdit);
2139 QString str = e->mimeData()->text();
2140
2141 if (!str.isNull() && !d->control->isReadOnly()) {
2142 if (e->source() == this && e->dropAction() == Qt::CopyAction)
2143 deselect();
2144 int cursorPos = d->xToPos(e->position().toPoint().x());
2145 int selStart = cursorPos;
2146 int oldSelStart = d->control->selectionStart();
2147 int oldSelEnd = d->control->selectionEnd();
2148 d->control->moveCursor(cursorPos, false);
2149 d->cursorVisible = false;
2150 e->acceptProposedAction();
2151 insert(str);
2152 if (e->source() == this) {
2153 if (e->dropAction() == Qt::MoveAction) {
2154 if (selStart > oldSelStart && selStart <= oldSelEnd)
2155 setSelection(oldSelStart, str.size());
2156 else if (selStart > oldSelEnd)
2157 setSelection(selStart - str.size(), str.size());
2158 else
2159 setSelection(selStart, str.size());
2160 } else {
2161 setSelection(selStart, str.size());
2162 }
2163 }
2164 } else {
2165 e->ignore();
2166 update();
2167 }
2168}
2169
2170#endif // QT_CONFIG(draganddrop)
2171
2172#ifndef QT_NO_CONTEXTMENU
2197
2205{
2206 Q_D(QLineEdit);
2207 QMenu *popup = new QMenu(this);
2208 popup->setObjectName("qt_edit_menu"_L1);
2209 QAction *action = nullptr;
2210
2211 if (!isReadOnly()) {
2212 action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo));
2213 action->setEnabled(d->control->isUndoAvailable());
2214 action->setObjectName(QStringLiteral("edit-undo"));
2215 setActionIcon(action, QStringLiteral("edit-undo"));
2216 connect(action, &QAction::triggered, this, &QLineEdit::undo);
2217
2218 action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo));
2219 action->setEnabled(d->control->isRedoAvailable());
2220 action->setObjectName(QStringLiteral("edit-redo"));
2221 setActionIcon(action, QStringLiteral("edit-redo"));
2222 connect(action, &QAction::triggered, this, &QLineEdit::redo);
2223
2224 popup->addSeparator();
2225 }
2226
2227#ifndef QT_NO_CLIPBOARD
2228 if (!isReadOnly()) {
2229 action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut));
2230 action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText()
2231 && d->control->echoMode() == QLineEdit::Normal);
2232 action->setObjectName(QStringLiteral("edit-cut"));
2233 setActionIcon(action, QStringLiteral("edit-cut"));
2234 connect(action, &QAction::triggered, this, &QLineEdit::cut);
2235 }
2236
2237 action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy));
2238 action->setEnabled(d->control->hasSelectedText()
2239 && d->control->echoMode() == QLineEdit::Normal);
2240 action->setObjectName(QStringLiteral("edit-copy"));
2241 setActionIcon(action, QStringLiteral("edit-copy"));
2242 connect(action, &QAction::triggered, this, &QLineEdit::copy);
2243
2244 if (!isReadOnly()) {
2245 action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste));
2246 action->setEnabled(!d->control->isReadOnly() && !QGuiApplication::clipboard()->text().isEmpty());
2247 action->setObjectName(QStringLiteral("edit-paste"));
2248 setActionIcon(action, QStringLiteral("edit-paste"));
2250 }
2251#endif
2252
2253 if (!isReadOnly()) {
2254 action = popup->addAction(QLineEdit::tr("Delete"));
2255 action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText());
2256 action->setObjectName(QStringLiteral("edit-delete"));
2257 setActionIcon(action, QStringLiteral("edit-delete"));
2258 connect(action, &QAction::triggered,
2259 d->control, &QWidgetLineControl::_q_deleteSelected);
2260 }
2261
2262 if (!popup->isEmpty())
2263 popup->addSeparator();
2264
2265 action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll));
2266 action->setEnabled(!d->control->text().isEmpty() && !d->control->allSelected());
2267 action->setObjectName(QStringLiteral("select-all"));
2268 setActionIcon(action, QStringLiteral("edit-select-all"));
2269 d->selectAllAction = action;
2271
2272 if (!d->control->isReadOnly() && QGuiApplication::styleHints()->useRtlExtensions()) {
2273 popup->addSeparator();
2274 QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, popup);
2275 popup->addMenu(ctrlCharacterMenu);
2276 }
2277 return popup;
2278}
2279#endif // QT_NO_CONTEXTMENU
2280
2283{
2284 Q_D(QLineEdit);
2285 switch(ev->type())
2286 {
2289 update();
2290 break;
2291 case QEvent::FontChange:
2292 d->control->setFont(font());
2293 break;
2295 {
2298 d->control->setPasswordCharacter(char16_t(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this)));
2299 d->control->setPasswordMaskDelay(style()->styleHint(QStyle::SH_LineEdit_PasswordMaskDelay, &opt, this));
2300 }
2301 update();
2302 break;
2304#if QT_CONFIG(toolbutton)
2305 for (const auto &e : d->trailingSideWidgets) { // Refresh icon to show arrow in right direction.
2307 static_cast<QLineEditIconButton *>(e.widget)->setIcon(d->clearButtonIcon());
2308 }
2309#endif
2310 d->positionSideWidgets();
2311 break;
2312 default:
2313 break;
2314 }
2316}
2317
2319
2320#include "moc_qlineedit.cpp"
static bool isEqual(const aiUVTransform &a, const aiUVTransform &b)
\inmodule QtGui
The QActionEvent class provides an event that is generated when a QAction is added,...
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
void setEnabled(bool)
Definition qaction.cpp:927
static QWidget * activePopupWidget()
Returns the active popup widget.
int startDragTime
the time in milliseconds that a mouse button must be held down before a drag and drop operation will ...
int doubleClickInterval
the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks
int startDragDistance
the minimum distance required for a drag and drop operation to start.
const QColor & color() const
Returns the brush color.
Definition qbrush.h:121
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
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
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
friend class QApplicationPrivate
\inmodule QtCore
Definition qcoreevent.h:45
@ ActionRemoved
Definition qcoreevent.h:153
@ LayoutDirectionChange
Definition qcoreevent.h:124
@ ReadOnlyChange
Definition qcoreevent.h:145
@ ShortcutOverride
Definition qcoreevent.h:158
@ StyleChange
Definition qcoreevent.h:136
@ FontChange
Definition qcoreevent.h:133
@ ActivationChange
Definition qcoreevent.h:135
@ WindowActivate
Definition qcoreevent.h:83
@ ContextMenu
Definition qcoreevent.h:119
Type type() const
Returns the event type.
Definition qcoreevent.h:304
Definition qflags.h:17
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
Qt::FocusReason reason() const
Returns the reason for this focus event.
Definition qevent.cpp:1569
\reentrant \inmodule QtGui
static QClipboard * clipboard()
Returns the object for interacting with the clipboard.
static QStyleHints * styleHints()
Returns the application's style hints.
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition qevent.h:56
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:625
const QString & preeditString() const
Returns the preedit text, i.e.
Definition qevent.h:650
const QString & commitString() const
Returns the text that should get added to (or replace parts of) the text of the editor widget.
Definition qevent.h:652
The QKeyEvent class describes a key event.
Definition qevent.h:424
static const int horizontalMargin
static const int verticalMargin
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
void setDragEnabled(bool b)
bool isRedoAvailable() const
void timerEvent(QTimerEvent *) override
\reimp
const QValidator * validator() const
Returns a pointer to the current input validator, or \nullptr if no validator has been set.
void mouseDoubleClickEvent(QMouseEvent *) override
\reimp
QString placeholderText
The line edit's placeholder text.
Definition qlineedit.h:47
int cursorPosition
The current cursor position for this line edit.
Definition qlineedit.h:37
QSize minimumSizeHint() const override
Returns a minimum size for the line edit.
Qt::CursorMoveStyle cursorMoveStyle
The movement style of the cursor in this line edit.
Definition qlineedit.h:48
bool isUndoAvailable() const
void setValidator(const QValidator *)
Sets the validator for values of line edit to v.
void setTextMargins(int left, int top, int right, int bottom)
void keyReleaseEvent(QKeyEvent *) override
\reimp
bool isClearButtonEnabled() const
QSize sizeHint() const override
Returns a recommended size for the widget.
QLineEdit(QWidget *parent=nullptr)
Constructs a line edit with no text.
void setClearButtonEnabled(bool enable)
bool event(QEvent *) override
\reimp
void contextMenuEvent(QContextMenuEvent *) override
Shows the standard context menu created with createStandardContextMenu().
QVariant inputMethodQuery(Qt::InputMethodQuery) const override
\reimp
void cursorForward(bool mark, int steps=1)
Moves the cursor forward steps characters.
int maxLength
The maximum permitted length of the text.
Definition qlineedit.h:33
QMargins textMargins() const
void cut()
Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode() is \l No...
void setCursorMoveStyle(Qt::CursorMoveStyle style)
int selectionEnd() const
Returns the index of the character directly after the selection in the line edit (or -1 if no text is...
void setAlignment(Qt::Alignment flag)
void selectAll()
Selects all the text (highlights it) and moves the cursor to the end.
void redo()
Redoes the last operation if redo is \l{QLineEdit::redoAvailable}{available}.
QRect cursorRect() const
void backspace()
If no text is selected, deletes the character to the left of the text cursor, and moves the cursor on...
void insert(const QString &)
Deletes any selected text, inserts newText, and validates the result.
EchoMode echoMode
The line edit's echo mode.
Definition qlineedit.h:35
bool hasSelectedText
Whether there is any text selected.
Definition qlineedit.h:40
bool hasAcceptableInput() const
void clear()
Clears the contents of the line edit.
int selectionStart() const
Returns the index of the first selected character in the line edit (or -1 if no text is selected).
QString displayText
The displayed text.
Definition qlineedit.h:36
void setPlaceholderText(const QString &)
int selectionLength() const
Returns the length of the selection.
void mouseReleaseEvent(QMouseEvent *) override
\reimp
void mousePressEvent(QMouseEvent *) override
\reimp
QMenu * createStandardContextMenu()
Creates the standard context menu, which is shown when the user clicks on the line edit with the righ...
bool hasFrame() const
void setReadOnly(bool)
void setInputMask(const QString &inputMask)
void cursorWordBackward(bool mark)
Moves the cursor one word backward.
QString selectedText
The selected text.
Definition qlineedit.h:41
void end(bool mark)
Moves the text cursor to the end of the line unless it is already there.
virtual void initStyleOption(QStyleOptionFrame *option) const
Initialize option with the values from this QLineEdit.
Definition qlineedit.cpp:73
~QLineEdit()
Destroys the line edit.
bool modified
Whether the line edit's contents has been modified by the user.
Definition qlineedit.h:39
void setCursorPosition(int)
@ TrailingPosition
Definition qlineedit.h:53
void setModified(bool)
void changeEvent(QEvent *) override
\reimp
void focusOutEvent(QFocusEvent *) override
\reimp
void copy() const
Copies the selected text to the clipboard, if there is any, and if echoMode() is \l Normal.
void cursorBackward(bool mark, int steps=1)
Moves the cursor back steps characters.
void home(bool mark)
Moves the text cursor to the beginning of the line unless it is already there.
void setText(const QString &)
void setEchoMode(EchoMode)
QString inputMask
The validation input mask.
Definition qlineedit.h:31
void setSelection(int, int)
Selects text from position start and for length characters.
void editingFinished()
This signal is emitted when the Return or Enter key is used, or if the line edit loses focus and its ...
void deselect()
Deselects any selected text.
void setFrame(bool)
QString text
The line edit's text.
Definition qlineedit.h:32
void paste()
Inserts the clipboard's text at the cursor position, deleting any selected text, providing the line e...
bool isModified() const
void keyPressEvent(QKeyEvent *) override
Converts the given key press event into a line edit action.
void cursorWordForward(bool mark)
Moves the cursor one word forward.
void del()
If no text is selected, deletes the character to the right of the text cursor.
EchoMode
This enum type describes how a line edit should display its contents.
Definition qlineedit.h:77
@ PasswordEchoOnEdit
Definition qlineedit.h:77
void inputMethodEvent(QInputMethodEvent *) override
\reimp
void focusInEvent(QFocusEvent *) override
\reimp
bool isReadOnly() const
int cursorPositionAt(const QPoint &pos)
Returns the cursor position under the point pos.
bool dragEnabled
Whether the line edit starts a drag if the user presses and moves the mouse on some selected text.
Definition qlineedit.h:42
void setMaxLength(int)
void mouseMoveEvent(QMouseEvent *) override
\reimp
void paintEvent(QPaintEvent *) override
\reimp
Qt::Alignment alignment
The alignment of the line edit.
Definition qlineedit.h:38
void undo()
Undoes the last operation if undo is \l{QLineEdit::undoAvailable}{available}.
\inmodule QtCore
Definition qmargins.h:24
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:115
constexpr int left() const noexcept
Returns the left margin.
Definition qmargins.h:106
constexpr int right() const noexcept
Returns the right margin.
Definition qmargins.h:112
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:109
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
bool isEmpty() const
Definition qmenu.cpp:2207
void popup(const QPoint &pos, QAction *at=nullptr)
Displays the menu so that the action atAction will be at the specified global position p.
Definition qmenu.cpp:2310
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition qmenu.cpp:1921
QAction * addMenu(QMenu *menu)
This convenience function adds menu as a submenu to this menu.
Definition qmenu.cpp:1877
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
\inmodule QtGui
Definition qevent.h:196
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:127
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
const QBrush & text() const
Returns the text foreground brush of the current color group.
Definition qpalette.h:88
@ Inactive
Definition qpalette.h:49
const QBrush & placeholderText() const
Definition qpalette.h:102
ColorGroup currentColorGroup() const
Returns the palette's current color group.
Definition qpalette.h:64
\inmodule QtGui
Definition qpen.h:28
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0.0 (ignoring the sign); otherwise returns fa...
Definition qpoint.h:338
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
\inmodule QtCore\reentrant
Definition qrect.h:30
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:119
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:116
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition qevent.h:117
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:994
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
\variable QStyleOptionFocusRect::backgroundColor
@ State_Sunken
Definition qstyle.h:69
@ State_ReadOnly
Definition qstyle.h:94
@ CT_LineEdit
Definition qstyle.h:561
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
Definition qstyle.cpp:2202
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=nullptr) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
@ SH_LineEdit_PasswordMaskDelay
Definition qstyle.h:690
@ SH_LineEdit_PasswordCharacter
Definition qstyle.h:620
@ SH_BlinkCursorWhenTextSelected
Definition qstyle.h:613
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=nullptr) const =0
Returns the sub-area for the given element as described in the provided style option.
@ PM_TextCursorWidth
Definition qstyle.h:520
@ PM_DefaultFrameWidth
Definition qstyle.h:420
@ PM_SmallIconSize
Definition qstyle.h:495
@ PE_PanelLineEdit
Definition qstyle.h:122
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
@ SE_LineEditContents
Definition qstyle.h:281
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
@ CursorBetweenCharacters
\inmodule QtCore
Definition qcoreevent.h:366
bool singleShot
whether the timer is a single-shot timer
Definition qtimer.h:22
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 setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Qt::LayoutDirection layoutDirection
the layout direction for this widget.
Definition qwidget.h:170
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
QWidget * nextInFocusChain() const
Returns the next widget in this widget's focus chain.
Definition qwidget.cpp:6845
QPointF mapToGlobal(const QPointF &) const
Translates the widget coordinate pos to global screen coordinates.
QPalette palette
the widget's palette
Definition qwidget.h:132
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7667
QFontMetrics fontMetrics() const
Returns the font metrics for the widget's current font.
Definition qwidget.h:847
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive key release events...
Definition qwidget.cpp:9641
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition qwidget.cpp:9913
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
bool isEnabled() const
Definition qwidget.h:814
void update()
Updates the widget unless updates are disabled or the widget is hidden.
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9382
Qt::InputMethodHints inputMethodHints
What input method specific hints the widget has.
Definition qwidget.h:178
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
QStyle * style() const
Definition qwidget.cpp:2600
QFont font
the font currently set for the widget
Definition qwidget.h:133
bool hasFocus() const
Definition qwidget.cpp:6446
virtual void focusOutEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition qwidget.cpp:9691
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
QCursor cursor
the cursor shape for this widget
Definition qwidget.h:135
void updateMicroFocus(Qt::InputMethodQuery query=Qt::ImQueryAll)
Updates the widget's micro focus and informs input methods that the state specified by query has chan...
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
void setInputMethodHints(Qt::InputMethodHints hints)
Definition qwidget.cpp:9971
void setCursor(const QCursor &)
Definition qwidget.cpp:4960
QString str
[2]
QString text
opt iconSize
uint alignment
QStyleOptionButton opt
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
InputMethodQuery
@ ImMaximumTextLength
@ ImTextBeforeCursor
@ ImAnchorRectangle
@ ImSurroundingText
@ ImCursorPosition
@ ImEnterKeyType
@ ImCurrentSelection
@ ImAbsolutePosition
@ ImReadOnly
@ ImFont
@ ImAnchorPosition
@ ImCursorRectangle
@ ImEnabled
@ ImTextAfterCursor
@ AlignRight
Definition qnamespace.h:146
@ AlignBottom
Definition qnamespace.h:154
@ AlignTop
Definition qnamespace.h:153
@ AlignHCenter
Definition qnamespace.h:148
@ AlignVertical_Mask
Definition qnamespace.h:161
@ AlignAbsolute
Definition qnamespace.h:150
@ LeftButton
Definition qnamespace.h:58
@ RightButton
Definition qnamespace.h:59
@ MiddleButton
Definition qnamespace.h:60
@ WA_MacShowFocusRect
Definition qnamespace.h:359
@ WA_InputMethodEnabled
Definition qnamespace.h:295
@ WA_DeleteOnClose
Definition qnamespace.h:321
LayoutDirection
@ LeftToRight
@ RightToLeft
@ NoFocus
Definition qnamespace.h:107
@ ArrowCursor
@ IBeamCursor
@ ImhNoPredictiveText
@ ImhSensitiveData
@ ImhHiddenText
@ ImhNoAutoUppercase
@ Key_Select
@ Key_Back
Definition qnamespace.h:846
@ Key_unknown
@ Key_No
@ ShiftModifier
@ ControlModifier
CursorMoveStyle
@ CopyAction
@ MoveAction
@ EnterKeyNext
@ ElideRight
Definition qnamespace.h:190
FocusReason
@ PopupFocusReason
@ BacktabFocusReason
@ MouseFocusReason
@ ActiveWindowFocusReason
@ TabFocusReason
@ ShortcutFocusReason
#define Q_UNLIKELY(x)
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
#define ACCEL_KEY(k)
Definition qlineedit.cpp:54
static const char clearButtonActionNameC[]
#define qWarning
Definition qlogging.h:166
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLboolean r
[2]
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLint left
GLint GLint bottom
GLbitfield flags
GLboolean enable
GLuint start
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
const GLubyte * c
GLsizei maxLength
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLuint GLenum option
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
QStyleSheetStyle * qt_styleSheet(QStyle *style)
#define emit
#define Q_UNUSED(x)
void setActionIcon(QAction *action, const QString &name)
const char property[13]
Definition qwizard.cpp:101
QWidget * panel
Definition settings.cpp:7
selection select(topLeft, bottomRight)
myAction setIcon(SomeIcon)
QMenu menu
[5]
QDBusArgument argument