#128764,增加搜索按下键切换焦点至搜索结果页;全屏增加字符输入直接切换搜索框

This commit is contained in:
lixueman 2022-07-18 10:29:15 +08:00
parent d1c570ba57
commit 4f319a7d7c
3 changed files with 29 additions and 1 deletions

View File

@ -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();
}
}

View File

@ -63,6 +63,7 @@ protected:
void initLayout();
void selectIconAnimation(const bool &flag);
void iconAnimationFinished();
void keyPressEvent(QKeyEvent *e);
private:
QAction *m_allAction = nullptr;

View File

@ -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<QStringList> arg)
m_searchAppThread->quit();
QVector<QStringList> m_data;
m_data.clear();
m_minSearchResultListView->verticalScrollBar()->setSliderPosition(0);
m_minSearchResultListView->addData(m_data, 3);
Q_FOREACH (QStringList appinfo, arg) {