Disable clear button in read-only QLineEdit.
Task-number: QTBUG-34315 Change-Id: I6c318879aee907c080e871a541da4ba5eadd71ed Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
parent
142c5ef9dd
commit
161e8653c3
@ -495,6 +495,7 @@ void QLineEdit::setClearButtonEnabled(bool enable)
|
||||
return;
|
||||
if (enable) {
|
||||
QAction *clearAction = new QAction(d->clearButtonIcon(), QString(), this);
|
||||
clearAction->setEnabled(!isReadOnly());
|
||||
clearAction->setObjectName(QLatin1String(clearButtonActionNameC));
|
||||
d->addAction(clearAction, 0, QLineEdit::TrailingPosition, QLineEditPrivate::SideWidgetClearButton | QLineEditPrivate::SideWidgetFadeInWithText);
|
||||
} else {
|
||||
@ -1336,6 +1337,7 @@ void QLineEdit::setReadOnly(bool enable)
|
||||
Q_D(QLineEdit);
|
||||
if (d->control->isReadOnly() != enable) {
|
||||
d->control->setReadOnly(enable);
|
||||
d->setClearButtonEnabled(!enable);
|
||||
setAttribute(Qt::WA_MacShowFocusRect, !enable);
|
||||
setAttribute(Qt::WA_InputMethodEnabled, d->shouldEnableInputMethod());
|
||||
#ifndef QT_NO_CURSOR
|
||||
|
@ -376,6 +376,16 @@ QIcon QLineEditPrivate::clearButtonIcon() const
|
||||
return QIcon(q->style()->standardPixmap(QStyle::SP_LineEditClearButton, &styleOption, q));
|
||||
}
|
||||
|
||||
void QLineEditPrivate::setClearButtonEnabled(bool enabled)
|
||||
{
|
||||
foreach (const SideWidgetEntry &e, trailingSideWidgets) {
|
||||
if (e.flags & SideWidgetClearButton) {
|
||||
e.action->setEnabled(enabled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QLineEditPrivate::positionSideWidgets()
|
||||
{
|
||||
Q_Q(QLineEdit);
|
||||
|
@ -199,6 +199,7 @@ public:
|
||||
void removeAction(QAction *action);
|
||||
QSize iconSize() const;
|
||||
QIcon clearButtonIcon() const;
|
||||
void setClearButtonEnabled(bool enabled);
|
||||
void positionSideWidgets();
|
||||
inline bool hasSideWidgets() const { return !leadingSideWidgets.isEmpty() || !trailingSideWidgets.isEmpty(); }
|
||||
inline const SideWidgetEntryList &leftSideWidgetList() const
|
||||
|
@ -4097,6 +4097,9 @@ void tst_QLineEdit::clearButton()
|
||||
QTRY_COMPARE(filterModel->rowCount(), 1); // matches 'ab'
|
||||
QTest::mouseClick(clearButton, Qt::LeftButton, 0, QRect(QPoint(0, 0), clearButton->size()).center());
|
||||
QTRY_COMPARE(filterModel->rowCount(), 3);
|
||||
|
||||
filterLineEdit->setReadOnly(true); // QTBUG-34315
|
||||
QVERIFY(!clearButton->isEnabled());
|
||||
}
|
||||
|
||||
void tst_QLineEdit::sideWidgets()
|
||||
|
Loading…
Reference in New Issue
Block a user