Qt 6.x
The Qt SDK
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
229{
230}
231
244 : QWidget(*new QLineEditPrivate, parent, { })
245{
246 Q_D(QLineEdit);
247 d->init(contents);
248}
249
250
251
257{
258}
259
260
277{
278 Q_D(const QLineEdit);
279 return d->control->text();
280}
281
283{
284 Q_D(QLineEdit);
285 d->setText(text);
286}
287
307{
308 Q_D(const QLineEdit);
309 return d->placeholderText;
310}
311
312void QLineEdit::setPlaceholderText(const QString& placeholderText)
313{
314 Q_D(QLineEdit);
315 if (d->placeholderText != placeholderText) {
316 d->placeholderText = placeholderText;
317 if (d->shouldShowPlaceholderText())
318 update();
319 }
320}
321
337{
338 Q_D(const QLineEdit);
339 return d->control->displayText();
340}
341
342
362{
363 Q_D(const QLineEdit);
364 return d->control->maxLength();
365}
366
368{
369 Q_D(QLineEdit);
370 d->control->setMaxLength(maxLength);
371}
372
381{
382 Q_D(const QLineEdit);
383 return d->frame;
384}
385
405#if QT_CONFIG(action)
412void QLineEdit::addAction(QAction *action, ActionPosition position)
413{
414 Q_D(QLineEdit);
415 QWidget::addAction(action);
416 d->addAction(action, nullptr, position);
417}
418
427QAction *QLineEdit::addAction(const QIcon &icon, ActionPosition position)
428{
429 QAction *result = new QAction(icon, QString(), this);
431 return result;
432}
433#endif // QT_CONFIG(action)
446static const char clearButtonActionNameC[] = "_q_qlineeditclearaction";
447
449{
450#if QT_CONFIG(action)
451 Q_D(QLineEdit);
453 return;
454 if (enable) {
455 QAction *clearAction = new QAction(d->clearButtonIcon(), QString(), this);
456 clearAction->setEnabled(!isReadOnly());
458
460 auto widgetAction = d->addAction(clearAction, nullptr, QLineEdit::TrailingPosition, flags);
461 widgetAction->setVisible(!text().isEmpty());
462 } else {
463 QAction *clearAction = findChild<QAction *>(QLatin1StringView(clearButtonActionNameC));
464 Q_ASSERT(clearAction);
465 d->removeAction(clearAction);
466 delete clearAction;
467 }
468#else
470#endif // QT_CONFIG(action)
471}
472
474{
475#if QT_CONFIG(action)
476 return findChild<QAction *>(QLatin1StringView(clearButtonActionNameC));
477#else
478 return false;
479#endif
480}
481
483{
484 Q_D(QLineEdit);
485 d->frame = enable;
486 update();
488}
489
490
533{
534 Q_D(const QLineEdit);
535 return (EchoMode) d->control->echoMode();
536}
537
539{
540 Q_D(QLineEdit);
541 if (mode == (EchoMode)d->control->echoMode())
542 return;
543 Qt::InputMethodHints imHints = inputMethodHints();
544 imHints.setFlag(Qt::ImhHiddenText, mode == Password || mode == NoEcho);
545 imHints.setFlag(Qt::ImhNoAutoUppercase, mode != Normal);
546 imHints.setFlag(Qt::ImhNoPredictiveText, mode != Normal);
547 imHints.setFlag(Qt::ImhSensitiveData, mode != Normal);
548 setInputMethodHints(imHints);
549 d->control->setEchoMode(mode);
550 update();
551}
552
553
554#ifndef QT_NO_VALIDATOR
563{
564 Q_D(const QLineEdit);
565 return d->control->validator();
566}
567
589{
590 Q_D(QLineEdit);
591 d->control->setValidator(v);
592}
593#endif // QT_NO_VALIDATOR
594
595#if QT_CONFIG(completer)
612void QLineEdit::setCompleter(QCompleter *c)
613{
614 Q_D(QLineEdit);
615 if (c == d->control->completer())
616 return;
617 if (d->control->completer()) {
618 disconnect(d->control->completer(), nullptr, this, nullptr);
619 d->control->completer()->setWidget(nullptr);
620 if (d->control->completer()->parent() == this)
621 delete d->control->completer();
622 }
623 d->control->setCompleter(c);
624 if (!c)
625 return;
626 if (c->widget() == nullptr)
627 c->setWidget(this);
628 if (hasFocus()) {
629 QObject::connect(d->control->completer(), SIGNAL(activated(QString)),
630 this, SLOT(setText(QString)));
631 QObject::connect(d->control->completer(), SIGNAL(highlighted(QString)),
632 this, SLOT(_q_completionHighlighted(QString)));
633 }
634}
635
641QCompleter *QLineEdit::completer() const
642{
643 Q_D(const QLineEdit);
644 return d->control->completer();
645}
646
647#endif // QT_CONFIG(completer)
648
657{
658 Q_D(const QLineEdit);
660 QFontMetrics fm(font());
661 const int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this);
662 const QMargins tm = d->effectiveTextMargins();
663 int h = qMax(fm.height(), qMax(14, iconSize - 2)) + 2 * QLineEditPrivate::verticalMargin
664 + tm.top() + tm.bottom()
665 + d->topmargin + d->bottommargin;
667 + tm.left() + tm.right()
668 + d->leftmargin + d->rightmargin; // "some"
671 return style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h), this);
672}
673
674
682{
683 Q_D(const QLineEdit);
686 const QMargins tm = d->effectiveTextMargins();
688 + tm.top() + tm.bottom()
689 + d->topmargin + d->bottommargin;
691 + tm.left() + tm.right()
692 + d->leftmargin + d->rightmargin;
695 return style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h), this);
696}
697
698
709{
710 Q_D(const QLineEdit);
711 return d->control->cursorPosition();
712}
713
715{
716 Q_D(QLineEdit);
717 d->control->setCursorPosition(pos);
718}
719
720// ### What should this do if the point is outside of contentsRect? Currently returns 0.
725{
726 Q_D(QLineEdit);
727 return d->xToPos(pos.x());
728}
729
730
731
744Qt::Alignment QLineEdit::alignment() const
745{
746 Q_D(const QLineEdit);
747 return QFlag(d->alignment);
748}
749
751{
752 Q_D(QLineEdit);
753 d->alignment = alignment;
754 update();
755}
756
757
766void QLineEdit::cursorForward(bool mark, int steps)
767{
768 Q_D(QLineEdit);
769 d->control->cursorForward(mark, steps);
770}
771
772
780void QLineEdit::cursorBackward(bool mark, int steps)
781{
782 cursorForward(mark, -steps);
783}
784
792{
793 Q_D(QLineEdit);
794 d->control->cursorWordForward(mark);
795}
796
805{
806 Q_D(QLineEdit);
807 d->control->cursorWordBackward(mark);
808}
809
810
820{
821 Q_D(QLineEdit);
822 d->control->backspace();
823}
824
834{
835 Q_D(QLineEdit);
836 d->control->del();
837}
838
848void QLineEdit::home(bool mark)
849{
850 Q_D(QLineEdit);
851 d->control->home(mark);
852}
853
863void QLineEdit::end(bool mark)
864{
865 Q_D(QLineEdit);
866 d->control->end(mark);
867}
868
869
889{
890 Q_D(const QLineEdit);
891 return d->control->isModified();
892}
893
894void QLineEdit::setModified(bool modified)
895{
896 Q_D(QLineEdit);
897 d->control->setModified(modified);
898}
899
914{
915 Q_D(const QLineEdit);
916 return d->control->hasSelectedText();
917}
918
932{
933 Q_D(const QLineEdit);
934 return d->control->selectedText();
935}
936
947{
948 Q_D(const QLineEdit);
949 return d->control->selectionStart();
950}
951
962{
963 Q_D(const QLineEdit);
964 return d->control->selectionEnd();
965}
966
976{
977 return selectionEnd() - selectionStart();
978}
979
988{
989 Q_D(QLineEdit);
990 if (Q_UNLIKELY(start < 0 || start > (int)d->control->end())) {
991 qWarning("QLineEdit::setSelection: Invalid start position (%d)", start);
992 return;
993 }
994
995 d->control->setSelection(start, length);
996
997 if (d->control->hasSelectedText()){
1000 if (!style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
1001 d->setCursorVisible(false);
1002 }
1003}
1004
1005
1016{
1017 Q_D(const QLineEdit);
1018 return d->control->isUndoAvailable();
1019}
1020
1032{
1033 Q_D(const QLineEdit);
1034 return d->control->isRedoAvailable();
1035}
1036
1046{
1047 Q_D(const QLineEdit);
1048 return d->dragEnabled;
1049}
1050
1052{
1053 Q_D(QLineEdit);
1054 d->dragEnabled = b;
1055}
1056
1074{
1075 Q_D(const QLineEdit);
1076 return d->control->cursorMoveStyle();
1077}
1078
1080{
1081 Q_D(QLineEdit);
1082 d->control->setCursorMoveStyle(style);
1083}
1084
1095{
1096 Q_D(const QLineEdit);
1097 return d->control->hasAcceptableInput();
1098}
1099
1108{
1110}
1111
1119{
1120 Q_D(QLineEdit);
1121 d->textMargins = margins;
1123 update();
1124}
1125
1133{
1134 Q_D(const QLineEdit);
1135 return d->textMargins;
1136}
1137
1221{
1222 Q_D(const QLineEdit);
1223 return d->control->inputMask();
1224}
1225
1226void QLineEdit::setInputMask(const QString &inputMask)
1227{
1228 Q_D(QLineEdit);
1229 d->control->setInputMask(inputMask);
1230}
1231
1242{
1243 Q_D(QLineEdit);
1244 d->control->selectAll();
1245}
1246
1254{
1255 Q_D(QLineEdit);
1256 d->control->deselect();
1257}
1258
1259
1267void QLineEdit::insert(const QString &newText)
1268{
1269// q->resetInputContext(); //#### FIX ME IN QT
1270 Q_D(QLineEdit);
1271 d->control->insert(newText);
1272}
1273
1280{
1281 Q_D(QLineEdit);
1282 d->resetInputMethod();
1283 d->control->clear();
1284}
1285
1292{
1293 Q_D(QLineEdit);
1294 d->resetInputMethod();
1295 d->control->undo();
1296}
1297
1302{
1303 Q_D(QLineEdit);
1304 d->resetInputMethod();
1305 d->control->redo();
1306}
1307
1308
1325{
1326 Q_D(const QLineEdit);
1327 return d->control->isReadOnly();
1328}
1329
1331{
1332 Q_D(QLineEdit);
1333 if (d->control->isReadOnly() != enable) {
1334 d->control->setReadOnly(enable);
1335 d->setClearButtonEnabled(!enable);
1337 setAttribute(Qt::WA_InputMethodEnabled, d->shouldEnableInputMethod());
1338#ifndef QT_NO_CURSOR
1340#endif
1343 update();
1344#if QT_CONFIG(accessibility)
1345 QAccessible::State changedState;
1346 changedState.readOnly = true;
1347 QAccessibleStateChangeEvent ev(this, changedState);
1348 QAccessible::updateAccessibility(&ev);
1349#endif
1350 }
1351}
1352
1353
1354#ifndef QT_NO_CLIPBOARD
1366{
1367 if (hasSelectedText()) {
1368 copy();
1369 del();
1370 }
1371}
1372
1373
1382{
1383 Q_D(const QLineEdit);
1384 d->control->copy();
1385}
1386
1398{
1399 Q_D(QLineEdit);
1400 d->control->paste();
1401}
1402
1403#endif // !QT_NO_CLIPBOARD
1404
1409{
1410 Q_D(QLineEdit);
1411 int timerId = ((QTimerEvent*)e)->timerId();
1412 if (false) {
1413#if QT_CONFIG(draganddrop)
1414 } else if (timerId == d->dndTimer.timerId()) {
1415 d->drag();
1416#endif
1417 }
1418 else if (timerId == d->tripleClickTimer.timerId())
1419 d->tripleClickTimer.stop();
1420}
1421
1425{
1426 Q_D(QLineEdit);
1427 if (e->type() == QEvent::ContextMenu) {
1428#ifndef QT_NO_IM
1429 if (d->control->composeMode())
1430 return true;
1431#endif
1432 //d->separate();
1433 } else if (e->type() == QEvent::WindowActivate) {
1434 QTimer::singleShot(0, this, SLOT(_q_handleWindowActivate()));
1435#ifndef QT_NO_SHORTCUT
1436 } else if (e->type() == QEvent::ShortcutOverride) {
1437 QKeyEvent *ke = static_cast<QKeyEvent*>(e);
1438 d->control->processShortcutOverrideEvent(ke);
1439#endif
1440 } else if (e->type() == QEvent::Show) {
1441 //In order to get the cursor blinking if QComboBox::setEditable is called when the combobox has focus
1442 if (hasFocus()) {
1443 d->control->setBlinkingCursorEnabled(true);
1446 if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty())
1447 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
1448 d->setCursorVisible(true);
1449 }
1450#if QT_CONFIG(action)
1451 } else if (e->type() == QEvent::ActionRemoved) {
1452 d->removeAction(static_cast<QActionEvent *>(e)->action());
1453#endif
1454 } else if (e->type() == QEvent::Resize) {
1455 d->positionSideWidgets();
1456 } else if (e->type() == QEvent::StyleChange) {
1457 d->initMouseYThreshold();
1458 }
1459#ifdef QT_KEYPAD_NAVIGATION
1460 if (QApplicationPrivate::keypadNavigationEnabled()) {
1461 if (e->type() == QEvent::EnterEditFocus) {
1462 end(false);
1463 d->setCursorVisible(true);
1464 d->control->setCursorBlinkEnabled(true);
1465 } else if (e->type() == QEvent::LeaveEditFocus) {
1466 d->setCursorVisible(false);
1467 d->control->setCursorBlinkEnabled(false);
1468 if (d->edited && (d->control->hasAcceptableInput()
1469 || d->control->fixup())) {
1471 d->edited = false;
1472 }
1473 }
1474 }
1475#endif
1476 return QWidget::event(e);
1477}
1478
1482{
1483 Q_D(QLineEdit);
1484
1485 d->mousePressPos = e->position().toPoint();
1486
1487 if (d->sendMouseEventToInputContext(e))
1488 return;
1489 if (e->button() == Qt::RightButton)
1490 return;
1491#ifdef QT_KEYPAD_NAVIGATION
1492 if (QApplication::QApplicationPrivate() && !hasEditFocus()) {
1493 setEditFocus(true);
1494 // Get the completion list to pop up.
1495 if (d->control->completer())
1496 d->control->completer()->complete();
1497 }
1498#endif
1499 if (d->tripleClickTimer.isActive() && (e->position().toPoint() - d->tripleClick).manhattanLength() <
1501 selectAll();
1502 return;
1503 }
1504 bool mark = e->modifiers() & Qt::ShiftModifier;
1505#ifdef Q_OS_ANDROID
1506 mark = mark && (d->imHints & Qt::ImhNoPredictiveText);
1507#endif // Q_OS_ANDROID
1508 int cursor = d->xToPos(e->position().toPoint().x());
1509#if QT_CONFIG(draganddrop)
1510 if (!mark && d->dragEnabled && d->control->echoMode() == Normal &&
1511 e->button() == Qt::LeftButton && d->inSelection(e->position().toPoint().x())) {
1512 if (!d->dndTimer.isActive())
1513 d->dndTimer.start(QApplication::startDragTime(), this);
1514 } else
1515#endif
1516 {
1517 d->control->moveCursor(cursor, mark);
1518 }
1519}
1520
1524{
1525 Q_D(QLineEdit);
1526
1527 if (e->buttons() & Qt::LeftButton) {
1528#if QT_CONFIG(draganddrop)
1529 if (d->dndTimer.isActive()) {
1530 if ((d->mousePressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance())
1531 d->drag();
1532 } else
1533#endif
1534 {
1535#ifndef Q_OS_ANDROID
1536 const bool select = true;
1537#else
1538 const bool select = (d->imHints & Qt::ImhNoPredictiveText);
1539#endif
1540#ifndef QT_NO_IM
1541 if (d->mouseYThreshold > 0 && e->position().toPoint().y() > d->mousePressPos.y() + d->mouseYThreshold) {
1543 d->control->home(select);
1544 else
1545 d->control->end(select);
1546 } else if (d->mouseYThreshold > 0 && e->position().toPoint().y() + d->mouseYThreshold < d->mousePressPos.y()) {
1548 d->control->end(select);
1549 else
1550 d->control->home(select);
1551 } else if (d->control->composeMode() && select) {
1552 int startPos = d->xToPos(d->mousePressPos.x());
1553 int currentPos = d->xToPos(e->position().toPoint().x());
1554 if (startPos != currentPos)
1555 d->control->setSelection(startPos, currentPos - startPos);
1556
1557 } else
1558#endif
1559 {
1560 d->control->moveCursor(d->xToPos(e->position().toPoint().x()), select);
1561 }
1562 }
1563 }
1564
1565 d->sendMouseEventToInputContext(e);
1566}
1567
1571{
1572 Q_D(QLineEdit);
1573 if (d->sendMouseEventToInputContext(e))
1574 return;
1575#if QT_CONFIG(draganddrop)
1576 if (e->button() == Qt::LeftButton) {
1577 if (d->dndTimer.isActive()) {
1578 d->dndTimer.stop();
1579 deselect();
1580 return;
1581 }
1582 }
1583#endif
1584#ifndef QT_NO_CLIPBOARD
1585 if (QGuiApplication::clipboard()->supportsSelection()) {
1586 if (e->button() == Qt::LeftButton) {
1587 d->control->copy(QClipboard::Selection);
1588 } else if (!d->control->isReadOnly() && e->button() == Qt::MiddleButton) {
1589 deselect();
1590 d->control->paste(QClipboard::Selection);
1591 }
1592 }
1593#endif
1594
1595 if (!isReadOnly() && rect().contains(e->position().toPoint()))
1596 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
1597 d->clickCausedFocus = 0;
1598}
1599
1603{
1604 Q_D(QLineEdit);
1605
1606 if (e->button() == Qt::LeftButton) {
1607 int position = d->xToPos(e->position().toPoint().x());
1608
1609 // exit composition mode
1610#ifndef QT_NO_IM
1611 if (d->control->composeMode()) {
1612 int preeditPos = d->control->cursor();
1613 int posInPreedit = position - d->control->cursor();
1614 int preeditLength = d->control->preeditAreaText().size();
1615 bool positionOnPreedit = false;
1616
1617 if (posInPreedit >= 0 && posInPreedit <= preeditLength)
1618 positionOnPreedit = true;
1619
1620 int textLength = d->control->end();
1621 d->control->commitPreedit();
1622 int sizeChange = d->control->end() - textLength;
1623
1624 if (positionOnPreedit) {
1625 if (sizeChange == 0)
1626 position = -1; // cancel selection, word disappeared
1627 else
1628 // ensure not selecting after preedit if event happened there
1629 position = qBound(preeditPos, position, preeditPos + sizeChange);
1630 } else if (position > preeditPos) {
1631 // adjust positions after former preedit by how much text changed
1632 position += (sizeChange - preeditLength);
1633 }
1634 }
1635#endif
1636
1637 if (position >= 0)
1638 d->control->selectWordAtPos(position);
1639
1640 d->tripleClickTimer.start(QApplication::doubleClickInterval(), this);
1641 d->tripleClick = e->position().toPoint();
1642 } else {
1643 d->sendMouseEventToInputContext(e);
1644 }
1645}
1646
1698{
1699 Q_D(QLineEdit);
1700 #ifdef QT_KEYPAD_NAVIGATION
1701 bool select = false;
1702 switch (event->key()) {
1703 case Qt::Key_Select:
1704 if (QApplicationPrivate::keypadNavigationEnabled()) {
1705 if (hasEditFocus()) {
1706 setEditFocus(false);
1707 if (d->control->completer() && d->control->completer()->popup()->isVisible())
1708 d->control->completer()->popup()->hide();
1709 select = true;
1710 }
1711 }
1712 break;
1713 case Qt::Key_Back:
1714 case Qt::Key_No:
1715 if (!QApplicationPrivate::keypadNavigationEnabled() || !hasEditFocus()) {
1716 event->ignore();
1717 return;
1718 }
1719 break;
1720 default:
1721 if (QApplicationPrivate::keypadNavigationEnabled()) {
1722 if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) {
1723 if (!event->text().isEmpty() && event->text().at(0).isPrint()
1724 && !isReadOnly())
1725 setEditFocus(true);
1726 else {
1727 event->ignore();
1728 return;
1729 }
1730 }
1731 }
1732 }
1733
1734
1735
1736 if (QApplicationPrivate::keypadNavigationEnabled() && !select && !hasEditFocus()) {
1737 setEditFocus(true);
1738 if (event->key() == Qt::Key_Select)
1739 return; // Just start. No action.
1740 }
1741#endif
1742 d->control->processKeyEvent(event);
1743 if (event->isAccepted())
1744 d->control->updateCursorBlinking();
1745}
1746
1751{
1752 Q_D(QLineEdit);
1753 if (!isReadOnly())
1754 d->handleSoftwareInputPanel();
1755 d->control->updateCursorBlinking();
1757}
1758
1765{
1766 Q_D(const QLineEdit);
1767 return d->cursorRect();
1768}
1769
1773{
1774 Q_D(QLineEdit);
1775
1776 if (echoMode() == PasswordEchoOnEdit && !d->control->passwordEchoEditing()) {
1777 // Clear the edit and reset to normal echo mode while entering input
1778 // method data; the echo mode switches back when the edit loses focus.
1779 // ### changes a public property, resets current content.
1780 d->updatePasswordEchoEditing(true);
1781 clear();
1782 }
1783
1784#ifdef QT_KEYPAD_NAVIGATION
1785 // Focus in if currently in navigation focus on the widget
1786 // Only focus in on preedits, to allow input methods to
1787 // commit text as they focus out without interfering with focus
1788 if (QApplicationPrivate::keypadNavigationEnabled()
1789 && hasFocus() && !hasEditFocus()
1790 && !e->preeditString().isEmpty())
1791 setEditFocus(true);
1792#endif
1793
1794 d->control->processInputMethodEvent(e);
1795
1796#if QT_CONFIG(completer)
1797 if (!e->commitString().isEmpty())
1798 d->control->complete(Qt::Key_unknown);
1799#endif
1800}
1801
1805{
1806#ifdef Q_OS_ANDROID
1807 // QTBUG-61652
1810 while (next && next != this && next->focusPolicy() == Qt::NoFocus)
1811 next = next->nextInFocusChain();
1812 if (next) {
1813 const auto nextYPos = next->mapToGlobal(QPoint(0, 0)).y();
1814 const auto currentYPos = mapToGlobal(QPoint(0, 0)).y();
1815 if (currentYPos < nextYPos)
1816 // Set EnterKey to KeyNext type only if the next widget
1817 // in the focus chain is below current QLineEdit
1818 return Qt::EnterKeyNext;
1819 }
1820 }
1821#endif
1823}
1824
1828{
1829 Q_D(const QLineEdit);
1830 switch(property) {
1831 case Qt::ImEnabled:
1832 return isEnabled();
1834 return d->cursorRect();
1836 return d->adjustedControlRect(d->control->anchorRect());
1837 case Qt::ImFont:
1838 return font();
1840 case Qt::ImCursorPosition: {
1841 const QPointF pt = argument.toPointF();
1842 if (!pt.isNull())
1843 return QVariant(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
1844 return QVariant(d->control->cursor()); }
1846 return QVariant(d->control->surroundingText());
1848 return QVariant(selectedText());
1850 return QVariant(maxLength());
1852 if (d->control->selectionStart() == d->control->selectionEnd())
1853 return QVariant(d->control->cursor());
1854 else if (d->control->selectionStart() == d->control->cursor())
1855 return QVariant(d->control->selectionEnd());
1856 else
1857 return QVariant(d->control->selectionStart());
1858 case Qt::ImReadOnly:
1859 return isReadOnly();
1861 const QPointF pt = argument.toPointF();
1862 if (!pt.isNull())
1863 return d->textBeforeCursor(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
1864 else
1865 return d->textBeforeCursor(d->control->cursor()); }
1866 case Qt::ImTextAfterCursor: {
1867 const QPointF pt = argument.toPointF();
1868 if (!pt.isNull())
1869 return d->textAfterCursor(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
1870 else
1871 return d->textAfterCursor(d->control->cursor()); }
1872 default:
1874 }
1875}
1876
1881{
1882 Q_D(QLineEdit);
1883 if (e->reason() == Qt::TabFocusReason ||
1884 e->reason() == Qt::BacktabFocusReason ||
1885 e->reason() == Qt::ShortcutFocusReason) {
1886 if (!d->control->inputMask().isEmpty())
1887 d->control->moveCursor(d->control->nextMaskBlank(0));
1888 else if (!d->control->hasSelectedText())
1889 selectAll();
1890 else
1892 } else if (e->reason() == Qt::MouseFocusReason) {
1893 d->clickCausedFocus = 1;
1895 }
1896#ifdef QT_KEYPAD_NAVIGATION
1897 if (!QApplicationPrivate::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason))) {
1898#endif
1899 d->control->setBlinkingCursorEnabled(true);
1902 if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty())
1903 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
1904 d->setCursorVisible(true);
1905#ifdef QT_KEYPAD_NAVIGATION
1906 d->control->setCancelText(d->control->text());
1907 }
1908#endif
1909#if QT_CONFIG(completer)
1910 if (d->control->completer()) {
1911 d->control->completer()->setWidget(this);
1912 QObject::connect(d->control->completer(), SIGNAL(activated(QString)),
1913 this, SLOT(setText(QString)));
1914 QObject::connect(d->control->completer(), SIGNAL(highlighted(QString)),
1915 this, SLOT(_q_completionHighlighted(QString)));
1916 }
1917#endif
1918 update();
1919}
1920
1924{
1925 Q_D(QLineEdit);
1926 if (d->control->passwordEchoEditing()) {
1927 // Reset the echomode back to PasswordEchoOnEdit when the widget loses
1928 // focus.
1929 d->updatePasswordEchoEditing(false);
1930 }
1931
1932 Qt::FocusReason reason = e->reason();
1933 if (reason != Qt::ActiveWindowFocusReason &&
1934 reason != Qt::PopupFocusReason)
1935 deselect();
1936
1937 d->setCursorVisible(false);
1938 d->control->setBlinkingCursorEnabled(false);
1939#ifdef QT_KEYPAD_NAVIGATION
1940 // editingFinished() is already emitted on LeaveEditFocus
1941 if (!QApplicationPrivate::keypadNavigationEnabled())
1942#endif
1943 if (reason != Qt::PopupFocusReason
1945 if (d->edited && (hasAcceptableInput() || d->control->fixup())) {
1947 d->edited = false;
1948 }
1949 }
1950#ifdef QT_KEYPAD_NAVIGATION
1951 d->control->setCancelText(QString());
1952#endif
1953#if QT_CONFIG(completer)
1954 if (d->control->completer()) {
1955 QObject::disconnect(d->control->completer(), nullptr, this, nullptr);
1956 }
1957#endif
1959}
1960
1964{
1965 Q_D(QLineEdit);
1966 QPainter p(this);
1967 QPalette pal = palette();
1968
1973 r = r.marginsRemoved(d->effectiveTextMargins());
1974 p.setClipRect(r);
1975
1977 int fmHeight = 0;
1978 if (d->shouldShowPlaceholderText())
1979 fmHeight = fm.boundingRect(d->placeholderText).height();
1980 else
1981 fmHeight = fm.boundingRect(d->control->text() + d->control->preeditAreaText()).height();
1982 fmHeight = qMax(fmHeight, fm.height());
1983
1984 Qt::Alignment va = QStyle::visualAlignment(d->control->layoutDirection(), QFlag(d->alignment));
1985 switch (va & Qt::AlignVertical_Mask) {
1986 case Qt::AlignBottom:
1987 d->vscroll = r.y() + r.height() - fmHeight - QLineEditPrivate::verticalMargin;
1988 break;
1989 case Qt::AlignTop:
1990 d->vscroll = r.y() + QLineEditPrivate::verticalMargin;
1991 break;
1992 default:
1993 //center
1994 d->vscroll = r.y() + (r.height() - fmHeight + 1) / 2;
1995 break;
1996 }
1997 QRect lineRect(r.x() + QLineEditPrivate::horizontalMargin, d->vscroll,
1998 r.width() - 2 * QLineEditPrivate::horizontalMargin, fmHeight);
1999
2000 if (d->shouldShowPlaceholderText()) {
2001 if (!d->placeholderText.isEmpty()) {
2002 const Qt::LayoutDirection layoutDir = d->placeholderText.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight;
2003 const Qt::Alignment alignPhText = QStyle::visualAlignment(layoutDir, QFlag(d->alignment));
2004 const QColor col = pal.placeholderText().color();
2005 QPen oldpen = p.pen();
2006 p.setPen(col);
2007 Qt::LayoutDirection oldLayoutDir = p.layoutDirection();
2008 p.setLayoutDirection(layoutDir);
2009
2010 const QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width());
2011 p.drawText(lineRect, alignPhText, elidedText);
2012 p.setPen(oldpen);
2013 p.setLayoutDirection(oldLayoutDir);
2014 }
2015 }
2016
2017 int cix = qRound(d->control->cursorToX());
2018
2019 // horizontal scrolling. d->hscroll is the left indent from the beginning
2020 // of the text line to the left edge of lineRect. we update this value
2021 // depending on the delta from the last paint event; in effect this means
2022 // the below code handles all scrolling based on the textline (widthUsed),
2023 // the line edit rect (lineRect) and the cursor position (cix).
2024 int widthUsed = qRound(d->control->naturalTextWidth()) + 1;
2025 if (widthUsed <= lineRect.width()) {
2026 // text fits in lineRect; use hscroll for alignment
2027 switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
2028 case Qt::AlignRight:
2029 d->hscroll = widthUsed - lineRect.width() + 1;
2030 break;
2031 case Qt::AlignHCenter:
2032 d->hscroll = (widthUsed - lineRect.width()) / 2;
2033 break;
2034 default:
2035 // Left
2036 d->hscroll = 0;
2037 break;
2038 }
2039 } else if (cix - d->hscroll >= lineRect.width()) {
2040 // text doesn't fit, cursor is to the right of lineRect (scroll right)
2041 d->hscroll = cix - lineRect.width() + 1;
2042 } else if (cix - d->hscroll < 0 && d->hscroll < widthUsed) {
2043 // text doesn't fit, cursor is to the left of lineRect (scroll left)
2044 d->hscroll = cix;
2045 } else if (widthUsed - d->hscroll < lineRect.width()) {
2046 // text doesn't fit, text document is to the left of lineRect; align
2047 // right
2048 d->hscroll = widthUsed - lineRect.width() + 1;
2049 } else {
2050 //in case the text is bigger than the lineedit, the hscroll can never be negative
2051 d->hscroll = qMax(0, d->hscroll);
2052 }
2053
2054 // the y offset is there to keep the baseline constant in case we have script changes in the text.
2055 // Needs to be kept in sync with QLineEditPrivate::adjustedControlRect
2056 QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent());
2057
2058 // draw text, selections and cursors
2059#ifndef QT_NO_STYLE_STYLESHEET
2060 if (QStyleSheetStyle* cssStyle = qt_styleSheet(style())) {
2061 cssStyle->styleSheetPalette(this, &panel, &pal);
2062 }
2063#endif
2064 p.setPen(pal.text().color());
2065
2067
2068#ifdef QT_KEYPAD_NAVIGATION
2069 if (!QApplicationPrivate::keypadNavigationEnabled() || hasEditFocus())
2070#endif
2071 if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){
2073 // Palette only used for selections/mask and may not be in sync
2074 if (d->control->palette() != pal
2075 || d->control->palette().currentColorGroup() != pal.currentColorGroup())
2076 d->control->setPalette(pal);
2077 }
2078
2079 // Asian users see an IM selection text as cursor on candidate
2080 // selection phase of input method, so the ordinary cursor should be
2081 // invisible if we have a preedit string. another condition is when inputmask
2082 // isn't empty,we don't need draw cursor,because cursor and character overlapping
2083 // area is white.
2084 if (d->cursorVisible && !d->control->isReadOnly() && d->control->inputMask().isEmpty())
2086
2087 d->control->setCursorWidth(style()->pixelMetric(QStyle::PM_TextCursorWidth, &panel));
2088 d->control->draw(&p, topLeft, r, flags);
2089
2090}
2091
2092
2093#if QT_CONFIG(draganddrop)
2096void QLineEdit::dragMoveEvent(QDragMoveEvent *e)
2097{
2098 Q_D(QLineEdit);
2099 if (!d->control->isReadOnly() && e->mimeData()->hasFormat("text/plain"_L1)) {
2100 e->acceptProposedAction();
2101 d->control->moveCursor(d->xToPos(e->position().toPoint().x()), false);
2102 d->cursorVisible = true;
2103 update();
2104 }
2105}
2106
2108void QLineEdit::dragEnterEvent(QDragEnterEvent * e)
2109{
2110 QLineEdit::dragMoveEvent(e);
2111}
2112
2114void QLineEdit::dragLeaveEvent(QDragLeaveEvent *)
2115{
2116 Q_D(QLineEdit);
2117 if (d->cursorVisible) {
2118 d->cursorVisible = false;
2119 update();
2120 }
2121}
2122
2124void QLineEdit::dropEvent(QDropEvent* e)
2125{
2126 Q_D(QLineEdit);
2127 QString str = e->mimeData()->text();
2128
2129 if (!str.isNull() && !d->control->isReadOnly()) {
2130 if (e->source() == this && e->dropAction() == Qt::CopyAction)
2131 deselect();
2132 int cursorPos = d->xToPos(e->position().toPoint().x());
2133 int selStart = cursorPos;
2134 int oldSelStart = d->control->selectionStart();
2135 int oldSelEnd = d->control->selectionEnd();
2136 d->control->moveCursor(cursorPos, false);
2137 d->cursorVisible = false;
2138 e->acceptProposedAction();
2139 insert(str);
2140 if (e->source() == this) {
2141 if (e->dropAction() == Qt::MoveAction) {
2142 if (selStart > oldSelStart && selStart <= oldSelEnd)
2143 setSelection(oldSelStart, str.size());
2144 else if (selStart > oldSelEnd)
2145 setSelection(selStart - str.size(), str.size());
2146 else
2147 setSelection(selStart, str.size());
2148 } else {
2149 setSelection(selStart, str.size());
2150 }
2151 }
2152 } else {
2153 e->ignore();
2154 update();
2155 }
2156}
2157
2158#endif // QT_CONFIG(draganddrop)
2159
2160#ifndef QT_NO_CONTEXTMENU
2179{
2182 menu->popup(event->globalPos());
2183 }
2184}
2185
2193{
2194 Q_D(QLineEdit);
2195 QMenu *popup = new QMenu(this);
2196 popup->setObjectName("qt_edit_menu"_L1);
2197 QAction *action = nullptr;
2198
2199 if (!isReadOnly()) {
2200 action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo));
2201 action->setEnabled(d->control->isUndoAvailable());
2202 setActionIcon(action, QStringLiteral("edit-undo"));
2203 connect(action, SIGNAL(triggered()), SLOT(undo()));
2204
2205 action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo));
2206 action->setEnabled(d->control->isRedoAvailable());
2207 setActionIcon(action, QStringLiteral("edit-redo"));
2208 connect(action, SIGNAL(triggered()), SLOT(redo()));
2209
2210 popup->addSeparator();
2211 }
2212
2213#ifndef QT_NO_CLIPBOARD
2214 if (!isReadOnly()) {
2215 action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut));
2216 action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText()
2217 && d->control->echoMode() == QLineEdit::Normal);
2218 setActionIcon(action, QStringLiteral("edit-cut"));
2219 connect(action, SIGNAL(triggered()), SLOT(cut()));
2220 }
2221
2222 action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy));
2223 action->setEnabled(d->control->hasSelectedText()
2224 && d->control->echoMode() == QLineEdit::Normal);
2225 setActionIcon(action, QStringLiteral("edit-copy"));
2226 connect(action, SIGNAL(triggered()), SLOT(copy()));
2227
2228 if (!isReadOnly()) {
2229 action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste));
2230 action->setEnabled(!d->control->isReadOnly() && !QGuiApplication::clipboard()->text().isEmpty());
2231 setActionIcon(action, QStringLiteral("edit-paste"));
2232 connect(action, SIGNAL(triggered()), SLOT(paste()));
2233 }
2234#endif
2235
2236 if (!isReadOnly()) {
2237 action = popup->addAction(QLineEdit::tr("Delete"));
2238 action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText());
2239 setActionIcon(action, QStringLiteral("edit-delete"));
2240 connect(action, SIGNAL(triggered()), d->control, SLOT(_q_deleteSelected()));
2241 }
2242
2243 if (!popup->isEmpty())
2244 popup->addSeparator();
2245
2246 action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll));
2247 action->setEnabled(!d->control->text().isEmpty() && !d->control->allSelected());
2248 setActionIcon(action, QStringLiteral("edit-select-all"));
2249 d->selectAllAction = action;
2250 connect(action, SIGNAL(triggered()), SLOT(selectAll()));
2251
2252 if (!d->control->isReadOnly() && QGuiApplication::styleHints()->useRtlExtensions()) {
2253 popup->addSeparator();
2254 QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, popup);
2255 popup->addMenu(ctrlCharacterMenu);
2256 }
2257 return popup;
2258}
2259#endif // QT_NO_CONTEXTMENU
2260
2263{
2264 Q_D(QLineEdit);
2265 switch(ev->type())
2266 {
2269 update();
2270 break;
2271 case QEvent::FontChange:
2272 d->control->setFont(font());
2273 break;
2275 {
2278 d->control->setPasswordCharacter(char16_t(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this)));
2279 d->control->setPasswordMaskDelay(style()->styleHint(QStyle::SH_LineEdit_PasswordMaskDelay, &opt, this));
2280 }
2281 update();
2282 break;
2284#if QT_CONFIG(toolbutton)
2285 for (const auto &e : d->trailingSideWidgets) { // Refresh icon to show arrow in right direction.
2287 static_cast<QLineEditIconButton *>(e.widget)->setIcon(d->clearButtonIcon());
2288 }
2289#endif
2290 d->positionSideWidgets();
2291 break;
2292 default:
2293 break;
2294 }
2296}
2297
2299
2300#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 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
QString text(Mode mode=Clipboard) const
Returns the clipboard text as plain text, or an empty string if the clipboard does not contain any te...
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:593
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:299
Definition qflags.h:17
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
\reentrant \inmodule QtGui
int height() const
Returns the height of the font.
QRect boundingRect(QChar) const
Returns the rectangle that is covered by ink if character ch were to be drawn at the origin of the co...
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
int maxWidth() const
Returns the width of the widest character in the font.
int horizontalAdvance(const QString &, int len=-1) const
Returns the horizontal advance in pixels of the first len characters of text.
int ascent() const
Returns the ascent of the font.
int leading() const
Returns the leading of the font.
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
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:624
The QKeyEvent class describes a key event.
Definition qevent.h:423
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 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)
Sets the margins around the text inside the frame to have the sizes left, top, right,...
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 (i.e.
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 one...
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()
This function creates the standard context menu which is shown when the user clicks on the line edit ...
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 pressed, or if the line edit loses focus and i...
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 lineedit 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:23
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:119
constexpr int left() const noexcept
Returns the left margin.
Definition qmargins.h:110
constexpr int right() const noexcept
Returns the right margin.
Definition qmargins.h:116
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:113
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:2185
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:2288
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition qmenu.cpp:1899
QAction * addMenu(QMenu *menu)
This convenience function adds menu as a submenu to this menu.
Definition qmenu.cpp:1855
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3124
\inmodule QtGui
Definition qevent.h:195
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3099
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:114
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
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:87
@ Inactive
Definition qpalette.h:48
const QBrush & placeholderText() const
Definition qpalette.h:101
ColorGroup currentColorGroup() const
Returns the palette's current color group.
Definition qpalette.h:63
\inmodule QtGui
Definition qpen.h:25
\inmodule QtCore\reentrant
Definition qpoint.h:214
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:333
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:338
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:328
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr QRect marginsRemoved(const QMargins &margins) const noexcept
Removes the margins from the rectangle, shrinking it.
Definition qrect.h:453
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:898
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
bool useRtlExtensions
the writing direction.
Definition qstylehints.h:42
\variable QStyleOptionFocusRect::backgroundColor
@ State_Sunken
Definition qstyle.h:69
@ State_ReadOnly
Definition qstyle.h:94
@ CT_LineEdit
Definition qstyle.h:559
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:2203
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:688
@ SH_LineEdit_PasswordCharacter
Definition qstyle.h:618
@ SH_BlinkCursorWhenTextSelected
Definition qstyle.h:611
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:518
@ PM_DefaultFrameWidth
Definition qstyle.h:420
@ PM_SmallIconSize
Definition qstyle.h:493
@ 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:359
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:64
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:6868
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:7753
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:9687
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition qwidget.cpp:9959
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:9428
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:8912
QStyle * style() const
Definition qwidget.cpp:2607
QFont font
the font currently set for the widget
Definition qwidget.h:133
bool hasFocus() const
Definition qwidget.cpp:6471
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:9737
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:3124
void setInputMethodHints(Qt::InputMethodHints hints)
void setCursor(const QCursor &)
Definition qwidget.cpp:4967
QString str
[2]
QString text
double e
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:145
@ AlignBottom
Definition qnamespace.h:153
@ AlignTop
Definition qnamespace.h:152
@ AlignHCenter
Definition qnamespace.h:147
@ AlignVertical_Mask
Definition qnamespace.h:160
@ AlignAbsolute
Definition qnamespace.h:149
@ LeftButton
Definition qnamespace.h:57
@ RightButton
Definition qnamespace.h:58
@ MiddleButton
Definition qnamespace.h:59
@ WA_MacShowFocusRect
Definition qnamespace.h:358
@ WA_InputMethodEnabled
Definition qnamespace.h:294
@ WA_DeleteOnClose
Definition qnamespace.h:320
LayoutDirection
@ LeftToRight
@ RightToLeft
@ NoFocus
Definition qnamespace.h:106
@ ArrowCursor
@ IBeamCursor
@ ImhNoPredictiveText
@ ImhSensitiveData
@ ImhHiddenText
@ ImhNoAutoUppercase
@ Key_Select
@ Key_Back
Definition qnamespace.h:841
@ Key_unknown
@ Key_No
@ ShiftModifier
@ ControlModifier
CursorMoveStyle
@ CopyAction
@ MoveAction
@ EnterKeyNext
@ ElideRight
Definition qnamespace.h:189
FocusReason
@ PopupFocusReason
@ BacktabFocusReason
@ MouseFocusReason
@ ActiveWindowFocusReason
@ TabFocusReason
@ ShortcutFocusReason
#define Q_UNLIKELY(x)
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:281
#define ACCEL_KEY(k)
Definition qlineedit.cpp:54
static const char clearButtonActionNameC[]
#define qWarning
Definition qlogging.h:162
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
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
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
myObject disconnect()
[26]
selection select(topLeft, bottomRight)
myAction setIcon(SomeIcon)
QMenu menu
[5]
QDBusArgument argument
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent