Improve behavior of cpp editor tool bar

The parse context drop down was taking a content based, fixed amount of
space in the editor tool bar, without being shrinkable.

That was especially bad if you have a long project / target name. When
working with a small window / split, the outline drop down would be
dropped from the tool bar.

This patch makes the parse context drop down shrinkable (with a small
minimum size), and gives the outline drop down a slightly higher
priority for getting tool bar space.

Task-number: QTCREATORBUG-19386
Change-Id: I87e3ee2e411a43b1f398ffd24fe5608e4df02af6
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Eike Ziller
2018-04-19 15:18:39 +02:00
parent 7421e59a77
commit 2dff9a03ac
3 changed files with 19 additions and 0 deletions

View File

@@ -134,6 +134,11 @@ ParseContextWidget::ParseContextWidget(ParseContextModel &parseContextModel, QWi
: QComboBox(parent)
, m_parseContextModel(parseContextModel)
{
setSizeAdjustPolicy(QComboBox::AdjustToContents);
QSizePolicy policy = sizePolicy();
policy.setHorizontalStretch(1);
policy.setHorizontalPolicy(QSizePolicy::Maximum);
setSizePolicy(policy);
// Set up context menu with a clear action
setContextMenuPolicy(Qt::ActionsContextMenu);
m_clearPreferredAction = new QAction(tr("Clear Preferred Parse Context"), this);
@@ -170,5 +175,16 @@ void ParseContextWidget::syncToModel()
CppEditorWidget::updateWidgetHighlighting(this, isPreferred);
}
QSize ParseContextWidget::minimumSizeHint() const
{
// QComboBox always returns the same from sizeHint() and minimumSizeHint().
// We want sizeHint() to be the preferred and maximum size
// (horizontalPolicy == Maximum), but want it to be shrinkable, which is not the case
// if the minimumSizeHint() is the same as sizeHint()
QSize size = QComboBox::minimumSizeHint();
size.setWidth(120);
return size;
}
} // namespace Internal
} // namespace CppEditor