From 3872ddb36aaf3f9a2c7d0739d70ce5861f58e91e Mon Sep 17 00:00:00 2001 From: Johannes Hilden Date: Sun, 15 Oct 2017 12:43:05 +0300 Subject: [PATCH] Give Auto Complete menu some time to disappear --- components/qtmaterialautocomplete.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/components/qtmaterialautocomplete.cpp b/components/qtmaterialautocomplete.cpp index 0fe6490..a34b48c 100644 --- a/components/qtmaterialautocomplete.cpp +++ b/components/qtmaterialautocomplete.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "qtmaterialflatbutton.h" /*! @@ -50,7 +52,7 @@ void QtMaterialAutoCompletePrivate::init() menuLayout->setContentsMargins(0, 0, 0, 0); menuLayout->setSpacing(0); - QObject::connect(q, SIGNAL(textChanged(QString)), q, SLOT(updateResults(QString))); + QObject::connect(q, SIGNAL(textEdited(QString)), q, SLOT(updateResults(QString))); } /*! @@ -86,7 +88,7 @@ void QtMaterialAutoComplete::updateResults(QString text) QString lookup(trimmed.toLower()); QStringList::iterator i; for (i = d->dataSource.begin(); i != d->dataSource.end(); ++i) { - if (i->toLower().startsWith(lookup)) { + if (i->toLower().indexOf(lookup) != -1) { results.push_back(*i); } } @@ -172,7 +174,13 @@ bool QtMaterialAutoComplete::eventFilter(QObject *watched, QEvent *event) switch (event->type()) { case QEvent::MouseButtonPress: { - d->menu->hide(); + QTimer::singleShot(300, this, [=](){ + d->menu->hide(); + }); + QtMaterialFlatButton *widget; + if ((widget = static_cast(watched))) { + setText(widget->text()); + } break; } default: