From 4f319a7d7cedaf98de7a591981cd49da674bbc36 Mon Sep 17 00:00:00 2001 From: lixueman Date: Mon, 18 Jul 2022 10:29:15 +0800 Subject: [PATCH] =?UTF-8?q?#128764=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8C=89=E4=B8=8B=E9=94=AE=E5=88=87=E6=8D=A2=E7=84=A6?= =?UTF-8?q?=E7=82=B9=E8=87=B3=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C=E9=A1=B5?= =?UTF-8?q?=EF=BC=9B=E5=85=A8=E5=B1=8F=E5=A2=9E=E5=8A=A0=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E7=9B=B4=E6=8E=A5=E5=88=87=E6=8D=A2=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UserInterface/full_mainwindow.cpp | 20 +++++++++++++++++++- src/UserInterface/full_mainwindow.h | 1 + src/UserInterface/mainwindow.cpp | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/UserInterface/full_mainwindow.cpp b/src/UserInterface/full_mainwindow.cpp index 826dc1d..d58f714 100755 --- a/src/UserInterface/full_mainwindow.cpp +++ b/src/UserInterface/full_mainwindow.cpp @@ -317,7 +317,7 @@ bool FullMainWindow::eventFilter(QObject *watched, QEvent *event) if (event->type() == QEvent::KeyPress) { QKeyEvent *ke = (QKeyEvent *)event; - if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) { + if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Down) { Q_EMIT sendSetFocusToResult(); } } @@ -371,6 +371,23 @@ void FullMainWindow::iconAnimationFinished() -Style::DropMenuWidth, 45))); } +void FullMainWindow::keyPressEvent(QKeyEvent *e) +{ + if (e->type() == QEvent::KeyPress) { + if ((e->key() >= Qt::Key_0 && e->key() <= Qt::Key_9) || (e->key() >= Qt::Key_A && e->key() <= Qt::Key_Z)) { + qDebug() << "void MainWindow::keyPressEvent(QKeyEvent *e)" << e->text(); + m_lineEdit->setFocus(); + m_lineEdit->setText(e->text()); + } + + if (e->key() == Qt::Key_Backspace) { + if (!m_lineEdit->text().isEmpty()) { + m_lineEdit->setText(""); + } + } + } +} + void FullMainWindow::selectIconAnimation(const bool &flag) { iconAnimation = new QPropertyAnimation(m_fullSelectMenuButton, "rotation", this); @@ -452,6 +469,7 @@ bool FullMainWindow::event(QEvent *event) } if (keyEvent->key() == Qt::Key_Escape) { + m_lineEdit->clear(); this->hide(); } } diff --git a/src/UserInterface/full_mainwindow.h b/src/UserInterface/full_mainwindow.h index 34a91ca..9592169 100755 --- a/src/UserInterface/full_mainwindow.h +++ b/src/UserInterface/full_mainwindow.h @@ -63,6 +63,7 @@ protected: void initLayout(); void selectIconAnimation(const bool &flag); void iconAnimationFinished(); + void keyPressEvent(QKeyEvent *e); private: QAction *m_allAction = nullptr; diff --git a/src/UserInterface/mainwindow.cpp b/src/UserInterface/mainwindow.cpp index 05f2f05..8614bc5 100755 --- a/src/UserInterface/mainwindow.cpp +++ b/src/UserInterface/mainwindow.cpp @@ -319,6 +319,7 @@ void MainWindow::initSearchUi() m_lineEdit->setStyleSheet(QString::fromUtf8("border-radius: 13px; border:1px solid rgba(5, 151, 255, 1); background: transparent;")); m_lineEdit->setFrame(false); m_lineEdit->setPlaceholderText(tr("Search")); + m_lineEdit->installEventFilter(this); m_cancelSearchPushButton = new QPushButton(m_minSearchPage); m_cancelSearchPushButton->setFixedSize(QSize(26, 26)); // m_cancelSearchPushButton->setStyleSheet(m_buttonStyle.arg("QPushButton")); @@ -1012,6 +1013,13 @@ bool MainWindow::eventFilter(QObject *target, QEvent *event) } } + if (target == m_lineEdit) { + if (ke->key() == Qt::Key_Down) { + m_minSearchResultListView->setFocus(); + return true; + } + } + if (target == m_minSelectButton) { if (ke->key() == Qt::Key_Down) { if (m_state == 0) { @@ -1099,6 +1107,7 @@ void MainWindow::recvSearchResult(QVector arg) m_searchAppThread->quit(); QVector m_data; m_data.clear(); + m_minSearchResultListView->verticalScrollBar()->setSliderPosition(0); m_minSearchResultListView->addData(m_data, 3); Q_FOREACH (QStringList appinfo, arg) {