From c74c9ba781ffbc07dda6a0936256dc00f89acfc8 Mon Sep 17 00:00:00 2001 From: iaom <18504285112@163.com> Date: Thu, 16 Sep 2021 14:58:07 +0800 Subject: [PATCH] Fix :The input box has no focus after press win+s sometimes. --- frontend/control/search-line-edit.cpp | 1 + frontend/mainwindow.cpp | 10 ++++++---- frontend/ukui-search-dbus-service.cpp | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/control/search-line-edit.cpp b/frontend/control/search-line-edit.cpp index 585f9e1..b17f8c7 100644 --- a/frontend/control/search-line-edit.cpp +++ b/frontend/control/search-line-edit.cpp @@ -102,6 +102,7 @@ SeachBarWidget::SeachBarWidget(QWidget *parent): QWidget(parent) { this->setFixedSize(m_searchLineEdit->width()+20, m_searchLineEdit->height()+20); m_ly->setContentsMargins(0,0,0,0); m_ly->addWidget(m_searchLineEdit); + this->setFocusProxy(m_searchLineEdit); connect(m_searchLineEdit, &SearchLineEdit::requestSearchKeyword, this, &SeachBarWidget::requestSearchKeyword); } diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 296ec4d..9c26169 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -66,7 +66,6 @@ MainWindow::MainWindow(QWidget *parent) : this->setWindowFlag(Qt::FramelessWindowHint); this->setAutoFillBackground(false); this->setFocusPolicy(Qt::StrongFocus); - this->setFocusProxy(this); this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); this->setWindowTitle(tr("ukui-search")); initUi(); @@ -127,6 +126,7 @@ void MainWindow::initUi() { m_searchResultPage = new SearchResultPage(this); m_searchResultPage->hide(); m_searchResultPage->move(0, 58); + this->setFocusProxy(m_searchBarWidget); // m_searchResultPage->show(); // m_searchWidget = new SeachBarWidget(this); @@ -183,9 +183,10 @@ void MainWindow::bootOptionsFilter(QString opt) { if(opt == "-s" || opt == "--show") { clearSearchResult(); centerToScreen(this); - this->show(); -// this->m_searchLineEdit->focusIn(); - this->raise(); + if(this->isHidden()) { + this->show(); + } + this->m_searchBarWidget->setFocus(); this->activateWindow(); } } @@ -543,6 +544,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event) bool MainWindow::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::ActivationChange) { + qDebug() << "QEvent::ActivationChange!!!!" << "active" << (QApplication::activeWindow() == this) << "isVisble" << (this->isVisible()); if(QApplication::activeWindow() != this) { tryHideMainwindow(); } diff --git a/frontend/ukui-search-dbus-service.cpp b/frontend/ukui-search-dbus-service.cpp index 5cf9831..538ca2d 100644 --- a/frontend/ukui-search-dbus-service.cpp +++ b/frontend/ukui-search-dbus-service.cpp @@ -2,6 +2,7 @@ using namespace Zeeker; void UkuiSearchDbusServices::showWindow(){ + qDebug() << "showWindow called"; m_mainWindow->bootOptionsFilter("-s"); }