Handle return key events in the search edit.

This commit is contained in:
Leonardo Zide 2017-08-21 23:16:32 -07:00
parent d39ec689a5
commit bb8e85d2c1
2 changed files with 21 additions and 1 deletions

View file

@ -8,8 +8,8 @@ lcSetsDatabaseDialog::lcSetsDatabaseDialog(QWidget* Parent)
ui(new Ui::lcSetsDatabaseDialog)
{
ui->setupUi(this);
ui->SearchEdit->installEventFilter(this);
connect(ui->SearchEdit, SIGNAL(returnPressed()), this, SLOT(on_SearchButton_clicked()));
connect(ui->SetsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(accept()));
connect(this, SIGNAL(finished(int)), this, SLOT(Finished(int)));
connect(&mNetworkManager, SIGNAL(finished(QNetworkReply*)), SLOT(DownloadFinished(QNetworkReply*)));
@ -34,6 +34,24 @@ QString lcSetsDatabaseDialog::GetSetDescription() const
return Current ? Current->text(1) : QString();
}
bool lcSetsDatabaseDialog::eventFilter(QObject* Object, QEvent* Event)
{
if (Event->type() == QEvent::KeyPress)
{
QKeyEvent* KeyEvent = static_cast<QKeyEvent*>(Event);
int Key = KeyEvent->key();
if (Key == Qt::Key_Return || Key == Qt::Key_Enter)
{
KeyEvent->accept();
on_SearchButton_clicked();
return true;
}
}
return QDialog::eventFilter(Object, Event);
}
void lcSetsDatabaseDialog::accept()
{
QTreeWidgetItem* Current = ui->SetsTree->currentItem();

View file

@ -23,6 +23,8 @@ public:
return mInventory;
}
virtual bool eventFilter(QObject* Object, QEvent* Event) override;
public slots:
void DownloadFinished(QNetworkReply* Reply);
void on_SearchButton_clicked();