Default focus in quick search edit after opening main window

Default focus in quick search edit after opening main window

Postby fightling » 20 Jan 2012, 14:16

Hi,

I have a tiny but nice improvement for KeePassX. I just inserted a line with a setFocus() call to the quick search edit control within the task bar. So now I can start entering a search string immediately after I've unlocked the DB or when I open the main window from the task bar. It's no magic - but to me it's very helpful.

--
void KeepassMainWindow::showEvent(QShowEvent* event){
if (IsLocked && !InUnLock && event->spontaneous()){
#ifndef Q_WS_MAC
showNormal(); // workaround for some graphic glitches
#endif
OnUnLockWorkspace();
}
QuickSearchEdit->setFocus(); // <-- insert line
QMainWindow::showEvent(event);
}
--
fightling
KPX user
 
Posts: 5
Joined: 02 Sep 2011, 00:52
Full Name: Patrick Hoffmann

Re: Default focus in quick search edit after opening main wi

Postby bernarpa » 11 Jan 2013, 12:31

I made this very same tweak, but in a different way (this is the patch):

Code: Select all
--- keepassx-0.4.3/src/mainwindow.cpp   2013-01-10 20:35:33.232930434 +0100
+++ keepassx-0.4.3/src/mainwindow.cpp.search_focus   2013-01-10 20:34:51.468791559 +0100
@@ -134,8 +134,10 @@ KeepassMainWindow::KeepassMainWindow(con
 
    createBookmarkActions();
    
-   if (showWindow)
+   if (showWindow) {
       show();
+      QuickSearchEdit->setFocus();
+   }
    else if (!config->showSysTrayIcon())
       showMinimized();
 }
@@ -610,6 +612,7 @@ void KeepassMainWindow::openFile(const Q
          return;
    }
    openDatabase(filename);
+   QuickSearchEdit->setFocus();
 }
 
 void KeepassMainWindow::OnFileOpen(){


I don't really know QT, so I didn't think about showEvent. What I tried to do is to find the code that gets called when:
    1 - The main window is started
    2 - A new KDB file is opened

Going for Ctrl+F right after opening KeePassX could have done just fine, but I'm lazy. :roll:
bernarpa
KPX user
 
Posts: 1
Joined: 11 Jan 2013, 12:20
Full Name: Paolo Bernardi


Return to Code discussion

Who is online

Users browsing this forum: No registered users and 1 guest