diff options
author | Fan RuiJie <fanruijie@uniontech.com> | 2021-05-20 17:02:08 +0800 |
---|---|---|
committer | Fan RuiJie <fanruijie@uniontech.com> | 2021-06-04 03:34:26 +0000 |
commit | dc794f7622bc00f7ca50fab65d6965695d6d2972 (patch) | |
tree | 2fc13180d90463a52f2b75c8aa82ec0b6e048d78 /src/widgets/widgets/qlineedit_p.cpp | |
parent | 57bb7cac64978f4949f2070e8666ea22bebdfadb (diff) |
Fix misplacement of placeholder text in QLineEdit with RTL content
The placeholder text was rendered in the wrong position after clicking
on the clear button in a QLineEdit with right-to-left content. The
button was still taking up space while it was fading out, so the first
paintEvent rendered the placeholder with space reserved for the clear
button. Once the button gets hidden, no new update was issued, so
garbage was left behind.
Fix this by not giving a fading-out clear button any margin space. The
result of this is that the placeholder text is visible underneath the
fading-out clear button. This is preferable to the placeholder text
being first rendered next to the fading-out clear button, and then
popping to the edge when the clear button is hidden (which would have
been the result of issuing a complete update for the line edit at the
end of the fade-out animation).
Fixes: QTBUG-93742
Pick-to: 6.1 6.0 5.15
Done-with: Volker Hilsheimer <volker.hilsheimer@qt.io>
Change-Id: Id0429362a60bba6839aa02068b00edb15e3ab8ab
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/widgets/qlineedit_p.cpp')
-rw-r--r-- | src/widgets/widgets/qlineedit_p.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index a5ac6a2211..a0a745ac4c 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -679,10 +679,18 @@ static int effectiveTextMargin(int defaultMargin, const QLineEditPrivate::SideWi if (widgets.empty()) return defaultMargin; - return defaultMargin + (parameters.margin + parameters.widgetWidth) * - int(std::count_if(widgets.begin(), widgets.end(), + const auto visibleSideWidgetCount = std::count_if(widgets.begin(), widgets.end(), [](const QLineEditPrivate::SideWidgetEntry &e) { - return e.widget->isVisibleTo(e.widget->parentWidget()); })); +#if QT_CONFIG(animation) + // a button that's fading out doesn't get any space + if (auto* iconButton = qobject_cast<QLineEditIconButton*>(e.widget)) + return iconButton->needsSpace(); + +#endif + return e.widget->isVisibleTo(e.widget->parentWidget()); + }); + + return defaultMargin + (parameters.margin + parameters.widgetWidth) * visibleSideWidgetCount; } QMargins QLineEditPrivate::effectiveTextMargins() const |