summaryrefslogtreecommitdiff
path: root/src/widgets
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 /src/widgets
parent1a097dc139d42f165af0c78ced0934b7e6747d9e (diff)
downloadqtbase-ab556d6b321bb02cec2a0c0705b1212377fde095.tar.gz
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 'src/widgets')
-rw-r--r--src/widgets/widgets/qcombobox.cpp26
-rw-r--r--src/widgets/widgets/qcombobox_p.h2
2 files changed, 23 insertions, 5 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 44e22555db..89dc8bf178 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -479,9 +479,9 @@ void QComboBoxPrivateContainer::updateScrollers()
view->verticalScrollBar()->minimum() < view->verticalScrollBar()->maximum()) {
bool needTop = view->verticalScrollBar()->value()
- > (view->verticalScrollBar()->minimum() + spacing());
+ > (view->verticalScrollBar()->minimum() + topMargin());
bool needBottom = view->verticalScrollBar()->value()
- < (view->verticalScrollBar()->maximum() - spacing()*2);
+ < (view->verticalScrollBar()->maximum() - bottomMargin() - topMargin());
if (needTop)
top->show();
else
@@ -572,13 +572,27 @@ void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView)
}
/*!
+ Returns the top/bottom vertical margin of the view.
+*/
+int QComboBoxPrivateContainer::topMargin() const
+{
+ if (const QListView *lview = qobject_cast<const QListView*>(view))
+ return lview->spacing();
+#ifndef QT_NO_TABLEVIEW
+ if (const QTableView *tview = qobject_cast<const QTableView*>(view))
+ return tview->showGrid() ? 1 : 0;
+#endif
+ return 0;
+}
+
+/*!
Returns the spacing between the items in the view.
*/
int QComboBoxPrivateContainer::spacing() const
{
QListView *lview = qobject_cast<QListView*>(view);
if (lview)
- return lview->spacing();
+ return 2 * lview->spacing(); // QListView::spacing is the padding around the item.
#ifndef QT_NO_TABLEVIEW
QTableView *tview = qobject_cast<QTableView*>(view);
if (tview)
@@ -2528,7 +2542,7 @@ void QComboBox::showPopup()
QModelIndex idx = d->model->index(i, d->modelColumn, parent);
if (!idx.isValid())
continue;
- listHeight += view()->visualRect(idx).height() + container->spacing();
+ listHeight += view()->visualRect(idx).height();
#ifndef QT_NO_TREEVIEW
if (d->model->hasChildren(idx) && treeView && treeView->isExpanded(idx))
toCheck.push(idx);
@@ -2540,12 +2554,14 @@ void QComboBox::showPopup()
}
}
}
+ if (count > 1)
+ listHeight += (count - 1) * container->spacing();
listRect.setHeight(listHeight);
}
{
// add the spacing for the grid on the top and the bottom;
- int heightMargin = 2*container->spacing();
+ int heightMargin = container->topMargin() + container->bottomMargin();
// add the frame of the container
int marginTop, marginBottom;
diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h
index becdde55ae..67b1aa6943 100644
--- a/src/widgets/widgets/qcombobox_p.h
+++ b/src/widgets/widgets/qcombobox_p.h
@@ -214,6 +214,8 @@ public:
QAbstractItemView *itemView() const;
void setItemView(QAbstractItemView *itemView);
int spacing() const;
+ int topMargin() const;
+ int bottomMargin() const { return topMargin(); }
void updateTopBottomMargin();
QTimer blockMouseReleaseTimer;