Workaround for FilterComboBox cutting off entries

This commit is contained in:
WarmUpTill 2025-10-14 20:29:55 +02:00 committed by WarmUpTill
parent 0b77ef5081
commit 10d45c67d6
2 changed files with 20 additions and 3 deletions

View File

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

View File

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