Skip to content

Commit

Permalink
Fix Suggestion Flickering when Typing
Browse files Browse the repository at this point in the history
setCompleter call setCompletionPrefix on typing which flicker
  • Loading branch information
ShaopengLin committed Oct 21, 2024
1 parent ec39c09 commit 9982a22
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) :

/* The items should be less than fetch size to enable scrolling. */
m_completer.setMaxVisibleItems(SuggestionListWorker::getFetchSize() / 2);
setCompleter(&m_completer);
m_completer.setWidget(this);

/* QCompleter's uses default list views, which do not have headers. */
m_completer.setPopup(m_suggestionView);
Expand Down Expand Up @@ -171,9 +171,18 @@ void SearchBarLineEdit::focusInEvent( QFocusEvent* event)
if (event->reason() == Qt::ActiveWindowFocusReason ||
event->reason() == Qt::MouseFocusReason ||
event->reason() == Qt::ShortcutFocusReason) {
connect(&m_completer, QOverload<const QString &>::of(&QCompleter::activated),
this, &QLineEdit::setText,Qt::UniqueConnection);

connect(&m_completer, QOverload<const QModelIndex &>::of(&QCompleter::activated),
this, QOverload<const QModelIndex &>::of(&SearchBarLineEdit::openCompletion),
Qt::UniqueConnection);

connect(&m_completer, QOverload<const QModelIndex &>::of(&QCompleter::highlighted), this,
[=](const QModelIndex &index){
setText(index.isValid() ? index.data().toString() : m_searchbarInput);
},
Qt::UniqueConnection);
}
QLineEdit::focusInEvent(event);
}
Expand All @@ -185,6 +194,7 @@ void SearchBarLineEdit::focusOutEvent(QFocusEvent* event)
setText(m_title);
}
deselect();
disconnect(&m_completer, nullptr, this, nullptr);
return QLineEdit::focusOutEvent(event);
}

Expand Down

0 comments on commit 9982a22

Please sign in to comment.