diff options
Diffstat (limited to 'src/widgets/widgets/qscrollarea.cpp')
-rw-r--r-- | src/widgets/widgets/qscrollarea.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/widgets/widgets/qscrollarea.cpp b/src/widgets/widgets/qscrollarea.cpp index f7a4f8e446..e8fdadb648 100644 --- a/src/widgets/widgets/qscrollarea.cpp +++ b/src/widgets/widgets/qscrollarea.cpp @@ -196,7 +196,23 @@ void QScrollAreaPrivate::updateScrollBars() if (resizable) { if ((widget->layout() ? widget->layout()->hasHeightForWidth() : widget->sizePolicy().hasHeightForWidth())) { QSize p_hfw = p.expandedTo(min).boundedTo(max); - int h = widget->heightForWidth( p_hfw.width() ); + int h = widget->heightForWidth(p_hfw.width()); + // If the height we calculated requires a vertical scrollbar, + // then we need to constrain the width and calculate the height again, + // otherwise we end up flipping the scrollbar on and off all the time. + if (vbarpolicy == Qt::ScrollBarAsNeeded) { + int vbarWidth = vbar->sizeHint().width(); + QSize m_hfw = m.expandedTo(min).boundedTo(max); + // is there any point in searching? + if (widget->heightForWidth(m_hfw.width() - vbarWidth) <= m.height()) { + while (h > m.height() && vbarWidth) { + --vbarWidth; + --m_hfw.rwidth(); + h = widget->heightForWidth(m_hfw.width()); + } + } + max = QSize(m_hfw.width(), qMax(m_hfw.height(), h)); + } min = QSize(p_hfw.width(), qMax(p_hfw.height(), h)); } } |