QLineEdit: Make the clear button always the leftmost button
QLineEditIconButton currently draws a fully transparent pixmap in its paintEvent() function, when the line edit is empty. This does not work when there is another trailing QAction that is visible even when the line edit has no text, as reported in QTBUG-59957. To fix this issue, make sure the clear button is always the leftmost button. Task-number: QTBUG-59957 Change-Id: I8a4f96aae07856aa0e1053ebb338ba9bdf052a16 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
254f35ce98
commit
288bfb0bbd
@ -533,6 +533,17 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
// QTBUG-59957: clear button should be the leftmost action.
|
||||
if (!before && !(flags & SideWidgetClearButton) && position == QLineEdit::TrailingPosition) {
|
||||
for (const SideWidgetEntry &e : trailingSideWidgets) {
|
||||
if (e.flags & SideWidgetClearButton) {
|
||||
before = e.action;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there is a 'before' action, it takes preference
|
||||
|
||||
// There's a bug in GHS compiler that causes internal error on the following code.
|
||||
|
@ -310,6 +310,7 @@ private slots:
|
||||
|
||||
void shortcutOverrideOnReadonlyLineEdit_data();
|
||||
void shortcutOverrideOnReadonlyLineEdit();
|
||||
void QTBUG59957_clearButtonLeftmostAction();
|
||||
|
||||
protected slots:
|
||||
void editingFinished();
|
||||
@ -4612,5 +4613,27 @@ void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit()
|
||||
QCOMPARE(spy.count(), activationCount);
|
||||
}
|
||||
|
||||
void tst_QLineEdit::QTBUG59957_clearButtonLeftmostAction()
|
||||
{
|
||||
QLineEdit lineEdit;
|
||||
lineEdit.setClearButtonEnabled(true);
|
||||
|
||||
auto clearButton = lineEdit.findChild<QLineEditIconButton *>();
|
||||
QVERIFY(clearButton);
|
||||
|
||||
QPixmap pixmap(16, 16);
|
||||
lineEdit.addAction(QIcon(pixmap), QLineEdit::TrailingPosition);
|
||||
lineEdit.addAction(QIcon(pixmap), QLineEdit::TrailingPosition);
|
||||
|
||||
lineEdit.show();
|
||||
|
||||
const auto buttons = lineEdit.findChildren<QLineEditIconButton *>();
|
||||
for (const auto button : buttons) {
|
||||
if (button == clearButton)
|
||||
continue;
|
||||
QVERIFY(clearButton->x() < button->x());
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QLineEdit)
|
||||
#include "tst_qlineedit.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user