From fe7ec24982d489c870c2f6696e01d0ea6c410bb6 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 4 Jul 2017 16:17:55 +0200 Subject: [PATCH] Fix size of locator popup The item delegate's sizeHint will only be correct after there are actual items to show. So behave similar to uniformRowHeights by waiting for the first data to arrive and then setting the size of the completion list and the popup. Task-number: QTCREATORBUG-18457 Change-Id: I7aa18988e07e21c2ec6587e83fb0de2dce6552ef Reviewed-by: David Schulz --- .../coreplugin/locator/locatorwidget.cpp | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/plugins/coreplugin/locator/locatorwidget.cpp b/src/plugins/coreplugin/locator/locatorwidget.cpp index 275b5b97377..107b49014a4 100644 --- a/src/plugins/coreplugin/locator/locatorwidget.cpp +++ b/src/plugins/coreplugin/locator/locatorwidget.cpp @@ -255,23 +255,29 @@ CompletionList::CompletionList(QWidget *parent) if (verticalScrollBar()) verticalScrollBar()->setAttribute(Qt::WA_MacMiniSize); } - const QStyleOptionViewItem &option = viewOptions(); - const QSize shint = itemDelegate()->sizeHint(option, QModelIndex()); - setFixedHeight(shint.height() * 17 + frameWidth() * 2); - installEventFilter(this); } void CompletionList::setModel(QAbstractItemModel *newModel) { + const auto updateSize = [this] { + if (model() && model()->rowCount() > 0) { + const QStyleOptionViewItem &option = viewOptions(); + const QSize shint = itemDelegate()->sizeHint(option, model()->index(0, 0)); + setFixedHeight(shint.height() * 17 + frameWidth() * 2); + disconnect(model(), &QAbstractItemModel::rowsInserted, this, 0); + } + }; + if (model()) { - disconnect(model(), &QAbstractItemModel::columnsInserted, - this, &CompletionList::resizeHeaders); + disconnect(model(), 0, this, 0); } QTreeView::setModel(newModel); if (newModel) { connect(newModel, &QAbstractItemModel::columnsInserted, this, &CompletionList::resizeHeaders); + connect(newModel, &QAbstractItemModel::rowsInserted, + this, updateSize); } } @@ -327,10 +333,11 @@ void LocatorPopup::updateWindow() bool LocatorPopup::event(QEvent *event) { - if (event->type() == QEvent::ParentChange) { + if (event->type() == QEvent::ParentChange) updateWindow(); - } else if (event->type() == QEvent::Show) - updateGeometry(); + // completion list resizes after first items are shown --> LayoutRequest + else if (event->type() == QEvent::Show || event->type() == QEvent::LayoutRequest) + QTimer::singleShot(0, this, &LocatorPopup::updateGeometry); return QWidget::event(event); }