tests/auto/qcombobox/tst_qcombobox.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
--- a/tests/auto/qcombobox/tst_qcombobox.cpp	Wed Jun 23 19:07:03 2010 +0300
+++ b/tests/auto/qcombobox/tst_qcombobox.cpp	Tue Jul 06 15:10:48 2010 +0300
@@ -156,6 +156,7 @@
     void resetModel();
     void keyBoardNavigationWithMouse();
     void task_QTBUG_1071_changingFocusEmitsActivated();
+    void maxVisibleItems();
 
 protected slots:
     void onEditTextChanged( const QString &newString );
@@ -2529,5 +2530,34 @@
     QTRY_COMPARE(spy.count(), 1);
 }
 
+void tst_QComboBox::maxVisibleItems()
+{
+    QComboBox comboBox;
+    QCOMPARE(comboBox.maxVisibleItems(), 10); //default value.
+
+    QStringList content;
+    for(int i = 1; i < 50; i++)
+        content += QString::number(i);
+
+    comboBox.addItems(content);
+    comboBox.show();
+    comboBox.resize(200, comboBox.height());
+    QTRY_VERIFY(comboBox.isVisible());
+
+    comboBox.setMaxVisibleItems(5);
+    QCOMPARE(comboBox.maxVisibleItems(), 5);
+
+    comboBox.showPopup();
+    QTRY_VERIFY(comboBox.view());
+    QTRY_VERIFY(comboBox.view()->isVisible());
+
+    QAbstractItemView *v = comboBox.view();
+    int itemHeight = v->visualRect(v->model()->index(0,0)).height();
+    if (v->style()->styleHint(QStyle::SH_ComboBox_Popup))
+        QCOMPARE(v->viewport()->height(), itemHeight * comboBox.maxVisibleItems());
+    // QCombobox without a popup does not work, see QTBUG-760
+}
+
+
 QTEST_MAIN(tst_QComboBox)
 #include "tst_qcombobox.moc"