From 53022e04bb578c12cdc9460d7ce4eedefbc8c2e4 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Wed, 12 Nov 2014 17:13:22 +0300 Subject: Make the defaultSectionSize property of QHeaderView style dependent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../itemviews/qheaderview/tst_qheaderview.cpp | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp') 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() { -- cgit v1.2.3