summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-10-20 15:04:24 +0200
committerFriedemann Kleint <Friedemann.Kleint@digia.com>2014-10-22 06:21:54 +0200
commitab556d6b321bb02cec2a0c0705b1212377fde095 (patch)
treeea6e45e58b3481e69f20a33b97a95b200b9bed2e /tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
parent1a097dc139d42f165af0c78ced0934b7e6747d9e (diff)
Fix height of combo popup when the list view has non-zero spacing.
QListView::spacing() is the space around the item (layout margin), so the effective spacing is twice as big. This differs conceptionally from QTableView, which has a spacing of 1 and a line on top/bottom. Split up QComboBoxPrivateContainer::spacing() into functions return spacing and top/bottom margins to reflect this. Task-number: QTBUG-37865 Change-Id: I1ff812e7856e00a53f1119ef3304956cbb7cbfca Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp')
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index 54cf1af5d3..f6928f0b35 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -152,6 +152,7 @@ private slots:
void resetModel();
void keyBoardNavigationWithMouse();
void task_QTBUG_1071_changingFocusEmitsActivated();
+ void maxVisibleItems_data();
void maxVisibleItems();
void task_QTBUG_10491_currentIndexAndModelColumn();
void highlightedSignal();
@@ -2749,8 +2750,18 @@ void tst_QComboBox::task_QTBUG_1071_changingFocusEmitsActivated()
QTRY_COMPARE(spy.count(), 1);
}
+void tst_QComboBox::maxVisibleItems_data()
+{
+ QTest::addColumn<int>("spacing");
+ QTest::newRow("Default") << -1;
+ QTest::newRow("No spacing") << 0;
+ QTest::newRow("20") << -1;
+}
+
void tst_QComboBox::maxVisibleItems()
{
+ QFETCH(int, spacing);
+
QComboBox comboBox;
QCOMPARE(comboBox.maxVisibleItems(), 10); //default value.
@@ -2771,15 +2782,18 @@ void tst_QComboBox::maxVisibleItems()
QTRY_VERIFY(comboBox.view());
QTRY_VERIFY(comboBox.view()->isVisible());
- QAbstractItemView *v = comboBox.view();
- int itemHeight = v->visualRect(v->model()->index(0,0)).height();
- QListView *lv = qobject_cast<QListView*>(v);
- if (lv)
- itemHeight += lv->spacing();
+ QListView *listView = qobject_cast<QListView*>(comboBox.view());
+ QVERIFY(listView);
+ if (spacing >= 0)
+ listView->setSpacing(spacing);
+
+ const int itemHeight = listView->visualRect(listView->model()->index(0,0)).height()
+ + 2 * listView->spacing();
+
QStyleOptionComboBox opt;
opt.initFrom(&comboBox);
if (!comboBox.style()->styleHint(QStyle::SH_ComboBox_Popup, &opt))
- QCOMPARE(v->viewport()->height(), itemHeight * comboBox.maxVisibleItems());
+ QCOMPARE(listView->viewport()->height(), itemHeight * comboBox.maxVisibleItems());
}
void tst_QComboBox::task_QTBUG_10491_currentIndexAndModelColumn()