kiwix / kiwix-desktop

Kiwix for Windows and GNU/Linux desktops
https://download.kiwix.org/release/kiwix-desktop/
GNU General Public License v3.0
776 stars 101 forks source link

Clicking outside of Search Suggestion List Should Fall through #1200

Open ShaopengLin opened 2 months ago

ShaopengLin commented 2 months ago

Follow up from #1189 and Point 4 of comment

Qt's popup windows do not provide this fall-through behavior and we will need to implement our own.

One solution is to make the QCompleter::popup() as a Qt::Tool window with setWindowFlags(), which makes the window non-modal allowing clicks to fall through. The problem comes with:

  1. how to hide the popup on click.
  2. preventing flickers to the suggestions when typing as seen here.
  3. Keep all other suggestion list behavior the same.

Difficulty comes from the focus relationship between SearchBarLineEdit and QCompleter::popup(). QCompleter::popup() proxies its focus to SearchBarLineEdit and our completion logic relies on focuses. Here is what I have tried:

1. Disconnect the proxy and handle each separately. This has deemed difficult as, popup needs focus to allow user keyboard navigations, and it will take focus away from the line edit. In addition, if we hide popup when it focuses out, it will flicker when user starts typing as it constantly races for focus with the line edit.

2. Keep the proxy and go for eventFilter. It is ad-hoc and would only work to filter out FocusOut events. Global click events are not reliable for this scenario since multiple clicks can happen at the same time for one click. Also, when users clicks minimize and maximize, the suggestions does not go away as the line edit doesn't lose focus.

There might be a lot more problems than what I described here when we switch to Qt::Tool window. I have not been able to find a solution, so maybe someone more experienced has more knowledge on how to make this work.