summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristoph Schleifenbaum <christoph.schleifenbaum@kdab.com>2015-04-22 13:06:32 +0200
committerThorbjørn Lund Martsum <tmartsum@gmail.com>2015-05-10 07:45:23 +0000
commit52c122e616f389bdeeffd3eedcd17c49e7e437c2 (patch)
treec722ccbc92ea172d7020160dea1a5c517b1f1b18 /tests
parentcca5cce205df1a7faefb3828af960326ba1ab846 (diff)
Improve QListView scroll bar calculation.
When both scroll bar's policies are set to ScrollBarAsNeeded, make sure the scroll bars are shown if needed and not show if not. Even the corner case, where one scroll bar's visibility depends on the other, is handled properly. Task-number: QTBUG-45470 Change-Id: I11d6ccf7c0b51644a5ce2d5c3fc59e2e4812755d Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> Reviewed-by: Thorbjørn Lindeijer <bjorn@lindeijer.nl>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index cea08435c9..32ca5ea7b7 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -47,6 +47,7 @@
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QDialog>
#include <QtWidgets/QStyledItemDelegate>
+#include <QtWidgets/QStyleFactory>
#if defined(Q_OS_WIN) || defined(Q_OS_WINCE)
# include <windows.h>
@@ -2348,11 +2349,34 @@ void tst_QListView::testViewOptions()
QCOMPARE(options.decorationPosition, QStyleOptionViewItem::Top);
}
+// make sure we have no transient scroll bars
+class TempStyleSetter
+{
+public:
+ TempStyleSetter()
+ : m_oldStyle(qApp->style())
+ {
+ m_oldStyle->setParent(0);
+ QListView tempView;
+ if (QApplication::style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, tempView.horizontalScrollBar()))
+ QApplication::setStyle(QStyleFactory::create("Fusion"));
+ }
+
+ ~TempStyleSetter()
+ {
+ QApplication::setStyle(m_oldStyle);
+ }
+private:
+ QStyle* m_oldStyle;
+};
+
void tst_QListView::taskQTBUG_39902_mutualScrollBars()
{
QWidget window;
window.resize(400, 300);
QListView *view = new QListView(&window);
+ // make sure we have no transient scroll bars
+ TempStyleSetter styleSetter;
QStandardItemModel model(200, 1);
const QSize itemSize(100, 20);
for (int i = 0; i < model.rowCount(); ++i)
@@ -2370,6 +2394,44 @@ void tst_QListView::taskQTBUG_39902_mutualScrollBars()
view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2);
// this will end up in a stack overflow, if QTBUG-39902 is not fixed
QTest::qWait(100);
+
+ // these tests do not apply with transient scroll bars enabled
+ QVERIFY (!view->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, view->horizontalScrollBar()));
+
+ // make it double as large, no scroll bars should be visible
+ view->resize((itemSize.width() + view->frameWidth() * 2) * 2, (model.rowCount() * itemSize.height() + view->frameWidth() * 2) * 2);
+ QTRY_VERIFY(!view->horizontalScrollBar()->isVisible());
+ QTRY_VERIFY(!view->verticalScrollBar()->isVisible());
+
+ // make it half the size, both scroll bars should be visible
+ view->resize((itemSize.width() + view->frameWidth() * 2) / 2, (model.rowCount() * itemSize.height() + view->frameWidth() * 2) / 2);
+ QTRY_VERIFY(view->horizontalScrollBar()->isVisible());
+ QTRY_VERIFY(view->verticalScrollBar()->isVisible());
+
+ // make it double as large, no scroll bars should be visible
+ view->resize((itemSize.width() + view->frameWidth() * 2) * 2, (model.rowCount() * itemSize.height() + view->frameWidth() * 2) * 2);
+ QTRY_VERIFY(!view->horizontalScrollBar()->isVisible());
+ QTRY_VERIFY(!view->verticalScrollBar()->isVisible());
+
+ // now, coming from the double size, resize it to the exactly matching size, still no scroll bars should be visible again
+ view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2);
+ QTRY_VERIFY(!view->horizontalScrollBar()->isVisible());
+ QTRY_VERIFY(!view->verticalScrollBar()->isVisible());
+
+ // now remove just one single pixel in height -> both scroll bars will show up since they depend on each other
+ view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2 - 1);
+ QTRY_VERIFY(view->horizontalScrollBar()->isVisible());
+ QTRY_VERIFY(view->verticalScrollBar()->isVisible());
+
+ // now remove just one single pixel in with -> both scroll bars will show up since they depend on each other
+ view->resize(itemSize.width() + view->frameWidth() * 2 - 1, model.rowCount() * itemSize.height() + view->frameWidth() * 2);
+ QTRY_VERIFY(view->horizontalScrollBar()->isVisible());
+ QTRY_VERIFY(view->verticalScrollBar()->isVisible());
+
+ // finally, coming from a size being to small, resize back to the exactly matching size -> both scroll bars should disappear again
+ view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2);
+ QTRY_VERIFY(!view->horizontalScrollBar()->isVisible());
+ QTRY_VERIFY(!view->verticalScrollBar()->isVisible());
}
QTEST_MAIN(tst_QListView)