7 Star 0 Fork 1

src-anolis-dde/qt5-qtbase-5.15

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
QTBUG-92366-Check-scrollbar-visibility-when-computing-QListView-Margins.patch 3.89 KB
一键复制 编辑 原始数据 按行查看 历史
From 55241556c113b47b5cb58f8cf72d939eef9683f6 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Tue, 5 Jul 2022 10:48:29 +0800
Subject: [PATCH]
QTBUG-92366-Check-scrollbar-visibility-when-computing-QListView-Margins
---
src/widgets/itemviews/qlistview.cpp | 2 +-
.../itemviews/qlistview/tst_qlistview.cpp | 55 +++++++++++++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 2d33759d..764855d8 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -1787,7 +1787,7 @@ void QListViewPrivate::prepareItemsLayout()
// maximumViewportSize() already takes scrollbar into account if policy is
// Qt::ScrollBarAlwaysOn but scrollbar extent must be deduced if policy
// is Qt::ScrollBarAsNeeded
- int verticalMargin = vbarpolicy==Qt::ScrollBarAsNeeded
+ int verticalMargin = (vbarpolicy == Qt::ScrollBarAsNeeded) && (flow == QListView::LeftToRight || vbar->isVisible())
? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr, vbar) + frameAroundContents
: 0;
int horizontalMargin = hbarpolicy==Qt::ScrollBarAsNeeded
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index 941ff523..83856380 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -167,6 +167,7 @@ private slots:
void taskQTBUG_51086_skippingIndexesInSelectedIndexes();
void taskQTBUG_47694_indexOutOfBoundBatchLayout();
void itemAlignment();
+ void spacingWithWordWrap();
void internalDragDropMove_data();
void internalDragDropMove();
};
@@ -2512,6 +2513,60 @@ void tst_QListView::taskQTBUG_47694_indexOutOfBoundBatchLayout()
view.scrollTo(model.index(batchSize - 1, 0));
}
+/*!
+ Verify fix for QTBUG-92366
+*/
+void tst_QListView::spacingWithWordWrap()
+{
+ const int listViewResizeCount = 200;
+ QWidget window;
+ window.resize(300, 200);
+ QListView lv(&window);
+
+ lv.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ lv.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ lv.setFlow(QListView::TopToBottom);
+ lv.setWordWrap(true);
+ lv.setSpacing(0);
+ lv.setGeometry(0, 0, 200, 150);
+
+ QStandardItem *it1 = new QStandardItem("qqqqqqqqqqqqqqqqqqqqq-ttttttttttttttttt");
+ QStandardItem *it2 = new QStandardItem("qqqqqqqqqqqqqqqq-tttttttttttt");
+ QStandardItemModel model;
+ lv.setModel(&model);
+ model.appendRow(it1);
+ model.appendRow(it2);
+
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+
+ QVERIFY(!lv.verticalScrollBar()->isVisible());
+ for (int i = 0; i < listViewResizeCount; ++i) {
+ lv.resize(lv.width() + 1, lv.height());
+ QRect rectForRowOne = lv.visualRect(model.index(0, 0));
+ QRect rectForRowTwo = lv.visualRect(model.index(1, 0));
+
+ QCOMPARE(rectForRowOne.y() + rectForRowOne.height(), rectForRowTwo.y());
+ }
+
+ lv.resize(200, 150);
+ const QStringList &stringList = generateList(QStringLiteral("Test_Abnormal_Spacing"), 30);
+ for (const QString &item_string : stringList) {
+ QStandardItem *item = new QStandardItem(item_string);
+ model.appendRow(item);
+ }
+
+ // test whether the height of item is correct if the vbar is shown.
+ QTRY_VERIFY(lv.verticalScrollBar()->isVisible());
+ for (int i = 0; i < listViewResizeCount; ++i) {
+ lv.resize(lv.width() + 1, lv.height());
+ QRect rectForRowOne = lv.visualRect(model.index(0, 0));
+ QRect rectForRowTwo = lv.visualRect(model.index(1, 0));
+
+ QCOMPARE(rectForRowOne.y() + rectForRowOne.height(), rectForRowTwo.y());
+ }
+}
+
void tst_QListView::itemAlignment()
{
auto item1 = new QStandardItem("111");
--
2.31.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-anolis-dde/qt5-qtbase-5.15.git
git@gitee.com:src-anolis-dde/qt5-qtbase-5.15.git
src-anolis-dde
qt5-qtbase-5.15
qt5-qtbase-5.15
a8.6

搜索帮助