Add option to disable filtering by typing in FilterComboBox

This commit is contained in:
WarmUpTill
2023-08-12 11:26:22 +02:00
committed by WarmUpTill
parent 68c6492c3f
commit a0b4df574b
7 changed files with 68 additions and 2 deletions

View File

@@ -7,9 +7,22 @@
namespace advss {
bool FilterComboBox::_filteringEnabled = false;
FilterComboBox::FilterComboBox(QWidget *parent, const QString &placehodler)
: QComboBox(parent)
{
// If the filtering behaviour of the FilterComboBox is disabled it is
// just a regular QComboBox with the option to set a placeholder so exit
// the constructor early.
if (!_filteringEnabled) {
if (!placehodler.isEmpty()) {
setPlaceholderText(placehodler);
}
return;
}
// Allow edit for completer but don't add new entries on pressing enter
setEditable(true);
setInsertPolicy(InsertPolicy::NoInsert);
@@ -31,6 +44,11 @@ FilterComboBox::FilterComboBox(QWidget *parent, const QString &placehodler)
&FilterComboBox::TextChagned);
}
void FilterComboBox::SetFilterBehaviourEnabled(bool value)
{
FilterComboBox::_filteringEnabled = value;
}
void FilterComboBox::focusOutEvent(QFocusEvent *event)
{
// Reset on invalid selection

View File

@@ -10,6 +10,7 @@ class FilterComboBox : public QComboBox {
public:
FilterComboBox(QWidget *parent = nullptr,
const QString &placehodler = "");
static void SetFilterBehaviourEnabled(bool);
protected:
void focusOutEvent(QFocusEvent *event) override;
@@ -20,6 +21,7 @@ private slots:
private:
int _lastCompleterHighlightRow = -1;
static bool _filteringEnabled;
};
} // namespace advss