Check scrollbar ScrollBarOverlap when computing QListView margins
When the listview setWordWrap is true and ScrollBarPolicy is ScrollBarAsNeeded, if QStyle::PM_ScrollView_ScrollBarOverlap returns true, the text displayed an empty line. Fix this by not reserving the width of the vertical scrollbar if the flow is TopToBottom and the vertical scrollbar, and QStyle returns true for PM_ScrollView_ScrollBarOverlap. Amends aeef92c3c33e4ebcb7e5d8dd955020f4f4600e84 Fixes: QTBUG-94248 Done-with: Volker Hilsheimer <volker.hilsheimer@qt.io> Change-Id: I4d47c7e86bbb86474cb1a99bb26d8b67f0e8a7e2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 0242be90606b377864c6fd02d5a8e0afaf635acf) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
07c87a56f2
commit
10ecb8ebc1
@ -1823,6 +1823,7 @@ void QListViewPrivate::prepareItemsLayout()
|
||||
// Qt::ScrollBarAlwaysOn but scrollbar extent must be deduced if policy
|
||||
// is Qt::ScrollBarAsNeeded
|
||||
int verticalMargin = (vbarpolicy == Qt::ScrollBarAsNeeded) && (flow == QListView::LeftToRight || vbar->isVisible())
|
||||
&& !q->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarOverlap, nullptr, vbar)
|
||||
? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr, vbar) + frameAroundContents
|
||||
: 0;
|
||||
int horizontalMargin = hbarpolicy==Qt::ScrollBarAsNeeded
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <QTest>
|
||||
#include <QTimer>
|
||||
#include <QtMath>
|
||||
#include <QProxyStyle>
|
||||
|
||||
#include <QtTest/private/qtesthelpers_p.h>
|
||||
#include <QtWidgets/private/qlistview_p.h>
|
||||
@ -170,6 +171,7 @@ private slots:
|
||||
void itemAlignment();
|
||||
void internalDragDropMove_data();
|
||||
void internalDragDropMove();
|
||||
void spacingWithWordWrap_data();
|
||||
void spacingWithWordWrap();
|
||||
};
|
||||
|
||||
@ -2765,8 +2767,37 @@ void tst_QListView::internalDragDropMove()
|
||||
/*!
|
||||
Verify fix for QTBUG-92366
|
||||
*/
|
||||
void tst_QListView::spacingWithWordWrap_data()
|
||||
{
|
||||
QTest::addColumn<bool>("scrollBarOverlap");
|
||||
|
||||
QTest::addRow("Without overlap") << false;
|
||||
QTest::addRow("With overlap") << true;
|
||||
}
|
||||
|
||||
void tst_QListView::spacingWithWordWrap()
|
||||
{
|
||||
QFETCH(bool, scrollBarOverlap);
|
||||
|
||||
class MyStyle : public QProxyStyle
|
||||
{
|
||||
bool scrollBarOverlap;
|
||||
public:
|
||||
MyStyle(bool scrollBarOverlap) : scrollBarOverlap(scrollBarOverlap) {}
|
||||
|
||||
int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
|
||||
const QWidget *widget = nullptr) const override{
|
||||
switch (metric) {
|
||||
case QStyle::PM_ScrollView_ScrollBarOverlap: return scrollBarOverlap;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QProxyStyle::pixelMetric(metric, option, widget);
|
||||
}
|
||||
};
|
||||
|
||||
QApplication::setStyle(new MyStyle(scrollBarOverlap));
|
||||
|
||||
const int listViewResizeCount = 200;
|
||||
QWidget window;
|
||||
window.resize(300, 200);
|
||||
|
Loading…
x
Reference in New Issue
Block a user