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 <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2017-07-04 16:17:55 +02:00
parent 7c6c808486
commit fe7ec24982

View File

@@ -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);
}