summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2014-11-12 17:13:22 +0300
committerAlexander Volkov <a.volkov@rusbitech.ru>2014-12-11 10:26:41 +0100
commit53022e04bb578c12cdc9460d7ce4eedefbc8c2e4 (patch)
tree8c70e70662ee3cb7e7922bb121f42119d570b195 /tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
parent6386bafb40f9d172f80d20cac824b7018e0a37a4 (diff)
Make the defaultSectionSize property of QHeaderView style dependent
Add new enum items PM_HeaderDefaultSectionSizeHorizontal and PM_HeaderDefaultSectionSizeVertical to QStyle and get corresponding values in QHeaderView. This way we get rid of some magic constants in QHeaderView and we can have reasonable values for the default section size for high-DPI displays. [ChangeLog][QtWidgets][QHeaderView] Default section size is now style-dependent by default. [ChangeLog][QtWidgets][QHeaderView] Added resetDefaultSectionSize(). Change-Id: I44e152c5cf0bec1e5d78e1e62f47a2d1f761dfbf Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp')
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 408e98b873..eacf2e51fd 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -176,6 +176,7 @@ private slots:
void moveSectionAndRemove();
void saveRestore();
void defaultSectionSizeTest();
+ void defaultSectionSizeTestStyles();
void defaultAlignment_data();
void defaultAlignment();
@@ -1679,6 +1680,41 @@ void tst_QHeaderView::defaultSectionSizeTest()
QVERIFY(hv->sectionSize(2) == 0); // section is hidden. It should not be resized.
}
+class TestHeaderViewStyle : public QProxyStyle
+{
+public:
+ TestHeaderViewStyle() : horizontalSectionSize(100) {}
+ int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const Q_DECL_OVERRIDE
+ {
+ if (metric == QStyle::PM_HeaderDefaultSectionSizeHorizontal)
+ return horizontalSectionSize;
+ else
+ return QProxyStyle::pixelMetric(metric, option, widget);
+ }
+ int horizontalSectionSize;
+};
+
+void tst_QHeaderView::defaultSectionSizeTestStyles()
+{
+ TestHeaderViewStyle style1;
+ TestHeaderViewStyle style2;
+ style1.horizontalSectionSize = 100;
+ style2.horizontalSectionSize = 200;
+
+ QHeaderView hv(Qt::Horizontal);
+ hv.setStyle(&style1);
+ QCOMPARE(hv.defaultSectionSize(), style1.horizontalSectionSize);
+ hv.setStyle(&style2);
+ QCOMPARE(hv.defaultSectionSize(), style2.horizontalSectionSize);
+ hv.setDefaultSectionSize(70);
+ QCOMPARE(hv.defaultSectionSize(), 70);
+ hv.setStyle(&style1);
+ QCOMPARE(hv.defaultSectionSize(), 70);
+ hv.resetDefaultSectionSize();
+ QCOMPARE(hv.defaultSectionSize(), style1.horizontalSectionSize);
+ hv.setStyle(&style2);
+ QCOMPARE(hv.defaultSectionSize(), style2.horizontalSectionSize);
+}
void tst_QHeaderView::defaultAlignment_data()
{