diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-05-25 18:11:10 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-05-31 01:26:08 +0000 |
commit | 1a081042abda3a32efeedeba7879017eed9237c6 (patch) | |
tree | b05f34124c5949cc0a1a13759084dbc48cc940c2 /src/widgets | |
parent | 8b31023ab62a4bf812e8b19cbfe703134b56d527 (diff) |
QComboBox: add space for scrollbar if needed after showing popup
QComboBox tests if a horizontal scrollbar is needed before sizing and
showing the popup, but QListView only knows whether a scrollbar is needed
only after laying itself out during the initial show and paint event.
So test whether the need has arisen as part of this initial layout, and
then provide the additional space. Resizing the widget after showing it
is not ideal, but in practice makes no visible difference (and it's
either way preferable to not being able to access the item covered by
the scrollbar).
Fixes: QTBUG-93736
Change-Id: I0bf077e18116ce174ae7f9218cb3b0dfa82964e1
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
(cherry picked from commit 11e88eaa6df629a2c23a60815a1f7826dd2ac31a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 6538a09210..a0b95367cf 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -2745,13 +2745,15 @@ void QComboBox::showPopup() QGuiApplication::inputMethod()->reset(); } - QScrollBar *sb = view()->horizontalScrollBar(); - Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy(); - bool needHorizontalScrollBar = (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn) - && sb->minimum() < sb->maximum(); - if (needHorizontalScrollBar) { + const QScrollBar *sb = view()->horizontalScrollBar(); + const auto needHorizontalScrollBar = [this, sb]{ + const Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy(); + return (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn) + && sb->minimum() < sb->maximum(); + }; + const bool neededHorizontalScrollBar = needHorizontalScrollBar(); + if (neededHorizontalScrollBar) listRect.adjust(0, 0, 0, sb->height()); - } // Hide the scrollers here, so that the listrect gets the full height of the container // If the scrollers are truly needed, the later call to container->updateScrollers() @@ -2794,6 +2796,11 @@ void QComboBox::showPopup() } } container->show(); + if (!neededHorizontalScrollBar && needHorizontalScrollBar()) { + listRect.adjust(0, 0, 0, sb->height()); + container->setGeometry(listRect); + } + container->updateScrollers(); view()->setFocus(); |