From fe966e5f48da975bfa63bb547398153b74fbd534 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Wed, 19 Sep 2012 17:45:25 +0200 Subject: Fix regression in QAbstractScrollArea The style hint SH_ScrollView_FrameOnlyAroundContents was currently being ignored by QAbstractScrollArea. This looks like an accidental regression following 10c6f015f45092040c281bb90a65179f598a00b1. This code path does not execute on mac so it should have no impact on that patch. Change-Id: I78ca0a6b87dfdd7d426acbb3ef49480390211af2 Reviewed-by: Christoph Schleifenbaum Reviewed-by: Jens Bache-Wiig --- tests/auto/widgets/styles/qstyle/tst_qstyle.cpp | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/auto/widgets/styles/qstyle') diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp index 2fb0ffe911..119ea33fc3 100644 --- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp +++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp @@ -72,6 +72,7 @@ #include #include #include +#include #include @@ -148,6 +149,7 @@ private slots: #endif void defaultFont(); void testDrawingShortcuts(); + void testFrameOnlyAroundContents(); private: void lineUpLayoutTest(QStyle *); QWidget *testWidget; @@ -763,6 +765,7 @@ public: int alignment; }; + void tst_QStyle::testDrawingShortcuts() { { @@ -796,5 +799,41 @@ void tst_QStyle::testDrawingShortcuts() } } +#define SCROLLBAR_SPACING 33 + +class FrameTestStyle : public QWindowsStyle { + int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const { + if (hint == QStyle::SH_ScrollView_FrameOnlyAroundContents) + return 1; + return QWindowsStyle ::styleHint(hint, opt, widget, returnData); + } + + int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget) const { + if (pm == QStyle::PM_ScrollView_ScrollBarSpacing) + return SCROLLBAR_SPACING; + return QWindowsStyle ::pixelMetric(pm, option ,widget); + } +}; + +void tst_QStyle::testFrameOnlyAroundContents() +{ + QScrollArea area; + area.setGeometry(0, 0, 200, 200); + QWindowsStyle winStyle; + FrameTestStyle frameStyle; + QWidget *widget = new QWidget(&area); + widget->setGeometry(0, 0, 400, 400); + area.setStyle(&winStyle); + area.verticalScrollBar()->setStyle(&winStyle); + area.setWidget(widget); + area.setVisible(true); + int viewPortWidth = area.viewport()->width(); + area.verticalScrollBar()->setStyle(&frameStyle); + area.setStyle(&frameStyle); + // Test that we reserve space for scrollbar spacing + QVERIFY(viewPortWidth == area.viewport()->width() + SCROLLBAR_SPACING); +} + + QTEST_MAIN(tst_QStyle) #include "tst_qstyle.moc" -- cgit v1.2.3