QLineEdit: Emit textEdited() when the clear button is clicked.
[ChangeLog][QtWidgets][QLineEdit] The signal textEdited() is now emitted when the user clicks the clear button created by setClearButtonEnabled() as well. Task-number: QTBUG-40287 Change-Id: Iacd303ffd1533f27cfa68a6120cdd370e3d31ddc Reviewed-by: Marc Mutz <marc.mutz@kdab.com>bb10
parent
a1d2bf257e
commit
63da7db055
|
|
@ -1,6 +1,6 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtWidgets module of the Qt Toolkit.
|
||||
|
|
@ -261,6 +261,7 @@ private:
|
|||
Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_updateNeeded(const QRect &))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_textChanged(const QString &))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_clearButtonClicked())
|
||||
};
|
||||
|
||||
#endif // QT_NO_LINEEDIT
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtWidgets module of the Qt Toolkit.
|
||||
|
|
@ -373,6 +373,15 @@ void QLineEditPrivate::_q_textChanged(const QString &text)
|
|||
}
|
||||
}
|
||||
|
||||
void QLineEditPrivate::_q_clearButtonClicked()
|
||||
{
|
||||
Q_Q(QLineEdit);
|
||||
if (!q->text().isEmpty()) {
|
||||
q->clear();
|
||||
emit q->textEdited(QString());
|
||||
}
|
||||
}
|
||||
|
||||
QSize QLineEditPrivate::iconSize() const
|
||||
{
|
||||
if (!m_iconSize.isValid()) // This might require style-specific handling (pixel metric).
|
||||
|
|
@ -448,7 +457,7 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE
|
|||
toolButton->setIcon(newAction->icon());
|
||||
toolButton->setOpacity(lastTextSize > 0 || !(flags & SideWidgetFadeInWithText) ? 1 : 0);
|
||||
if (flags & SideWidgetClearButton)
|
||||
QObject::connect(toolButton, SIGNAL(clicked()), q, SLOT(clear()));
|
||||
QObject::connect(toolButton, SIGNAL(clicked()), q, SLOT(_q_clearButtonClicked()));
|
||||
toolButton->setDefaultAction(newAction);
|
||||
w = toolButton;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,6 +195,7 @@ public:
|
|||
void drag();
|
||||
#endif
|
||||
void _q_textChanged(const QString &);
|
||||
void _q_clearButtonClicked();
|
||||
|
||||
int leftTextMargin; // use effectiveLeftTextMargin() in case of icon.
|
||||
int topTextMargin;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the test suite of the Qt Toolkit.
|
||||
|
|
@ -4185,8 +4185,14 @@ void tst_QLineEdit::clearButton()
|
|||
QTRY_COMPARE(filterModel->rowCount(), 2); // matches 'aa', 'ab'
|
||||
QTest::keyClick(filterLineEdit, 'b');
|
||||
QTRY_COMPARE(filterModel->rowCount(), 1); // matches 'ab'
|
||||
QTest::mouseClick(clearButton, Qt::LeftButton, 0, QRect(QPoint(0, 0), clearButton->size()).center());
|
||||
QSignalSpy spyEdited(filterLineEdit, &QLineEdit::textEdited);
|
||||
const QPoint clearButtonCenterPos = QRect(QPoint(0, 0), clearButton->size()).center();
|
||||
QTest::mouseClick(clearButton, Qt::LeftButton, 0, clearButtonCenterPos);
|
||||
QCOMPARE(spyEdited.count(), 1);
|
||||
QTest::mouseClick(clearButton, Qt::LeftButton, 0, clearButtonCenterPos);
|
||||
QTRY_COMPARE(filterModel->rowCount(), 3);
|
||||
QCoreApplication::processEvents();
|
||||
QCOMPARE(spyEdited.count(), 1);
|
||||
|
||||
filterLineEdit->setReadOnly(true); // QTBUG-34315
|
||||
QVERIFY(!clearButton->isEnabled());
|
||||
|
|
|
|||
Loading…
Reference in New Issue