summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-10-08 13:28:31 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-10-09 09:50:50 +0200
commitfe65df06c346086cccc658b0a42300766ffed12d (patch)
treecc083c20d5134b26f1d3db29df72d85ca3e55afa
parentc580fcbdf835b9b54709a1bbc873805b4764425a (diff)
Fix scrolling of QTableWidget within QGraphicsView
In the QGraphicsView branch of QWidget::scroll, scroll the children, too. Task-number: QTBUG-138381 Pick-to: 6.10 Change-Id: I77cb9288d5b9630dca659d7ef987d11914ed1e43 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/widgets/kernel/qwidget.cpp1
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp27
2 files changed, 28 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index dcd10d66240..0d3c6be10cc 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -11161,6 +11161,7 @@ void QWidget::scroll(int dx, int dy)
for (const QRect &rect : d->dirty)
proxy->update(rect.translated(dx, dy));
proxy->scroll(dx, dy, proxy->subWidgetRect(this));
+ d->scrollChildren(dx, dy); // QTBUG-138381: scroll item view cell widgets
return;
}
#endif
diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index 5295a2f8740..17acdea014e 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
@@ -22,6 +22,7 @@
#include <QtWidgets/qscrollbar.h>
#include <QtWidgets/qspinbox.h>
#include <QtWidgets/qstylefactory.h>
+#include <QtWidgets/qtablewidget.h>
#include <QtGui/qevent.h>
#include <QtGui/private/qhighdpiscaling_p.h>
@@ -173,6 +174,7 @@ private slots:
#endif
void forwardTouchEvent();
void touchEventPropagation();
+ void itemViewScroll();
};
// Subclass that exposes the protected functions.
@@ -4070,5 +4072,30 @@ void tst_QGraphicsProxyWidget::touchEventPropagation()
QCOMPARE(clickedSpy.size(), 0); // multi-touch event does not synthesize a mouse event
}
+void tst_QGraphicsProxyWidget::itemViewScroll()
+{
+ // QTBUG-138381: When scrolling an embedded item view, the cell widgets should move as well.
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+
+ QLabel *label{};
+ auto *table = new QTableWidget(1, 10);
+ for (int i = 0; i < 10; ++i) {
+ label = new QLabel(QString::number(1 + i));
+ table->setCellWidget(0, i, label);
+ }
+ scene.addWidget(table);
+ table->resize(300, 200);
+ table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+ table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+ view.resize(600, 600);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowActive(&view));
+ const int oldPos = label->x();
+ auto *horizontalScrollBar = table->horizontalScrollBar();
+ horizontalScrollBar->setValue(horizontalScrollBar->maximum() * 3 / 2);
+ QTRY_VERIFY(label->x() < oldPos);
+}
+
QTEST_MAIN(tst_QGraphicsProxyWidget)
#include "tst_qgraphicsproxywidget.moc"