diff --git a/lib/utils/filter-combo-box.cpp b/lib/utils/filter-combo-box.cpp index 491de79f..73de876f 100644 --- a/lib/utils/filter-combo-box.cpp +++ b/lib/utils/filter-combo-box.cpp @@ -84,6 +84,21 @@ void FilterComboBox::setItemText(int index, const QString &text) } } +QSize FilterComboBox::sizeHint() const +{ + QSize size = QComboBox::sizeHint(); + + if (!_filteringEnabled) { + return QComboBox::sizeHint(); + } + + QFontMetrics fm(font()); + int extra = fm.horizontalAdvance("X") * 2; // Add padding + size.setWidth(size.width() + extra); + + return size; +} + void FilterComboBox::focusOutEvent(QFocusEvent *event) { // Reset on invalid selection @@ -96,7 +111,7 @@ void FilterComboBox::focusOutEvent(QFocusEvent *event) _lastCompleterHighlightRow = -1; } -static int findXthOccurance(QComboBox *list, int count, const QString &value) +static int findXthOccurrence(QComboBox *list, int count, const QString &value) { if (value.isEmpty() || count < 1) { return -1; @@ -121,7 +136,7 @@ void FilterComboBox::CompleterHighlightChanged(const QModelIndex &index) { _lastCompleterHighlightRow = index.row(); const auto text = currentText(); - int idx = findXthOccurance(this, _lastCompleterHighlightRow, text); + int idx = findXthOccurrence(this, _lastCompleterHighlightRow, text); if (idx == -1) { return; } @@ -133,7 +148,7 @@ void FilterComboBox::TextChanged(const QString &text) auto c = completer(); const bool completerActive = c->completionCount() > 0; int count = completerActive ? _lastCompleterHighlightRow + 1 : 1; - int idx = findXthOccurance(this, count, text); + int idx = findXthOccurrence(this, count, text); if (idx == -1) { return; } diff --git a/lib/utils/filter-combo-box.hpp b/lib/utils/filter-combo-box.hpp index b506febf..efef8972 100644 --- a/lib/utils/filter-combo-box.hpp +++ b/lib/utils/filter-combo-box.hpp @@ -18,6 +18,8 @@ public: void setCurrentText(const QString &text); void setItemText(int index, const QString &text); + QSize sizeHint() const override; + protected: void focusOutEvent(QFocusEvent *event) override;