helloSystem / Menu

Global menu bar written in Qt
44 stars 14 forks source link

Clear search whenever Search menu is closed #95

Closed probonopd closed 2 years ago

probonopd commented 2 years ago

Currently the searchLineEdit only gets cleared when the user switches to another application.

It should be cleared as soon as the Search menu is closed for whatever reason.

image

Do you know how to do this @jsm222?

probably we need to do

searchLineEdit->clear();
searchLineEdit->textChanged("");

somewhere, but where? (I am looking for the equivalent of "onSearchMenuClosed" - do we need to use an event filter?)

jsm222 commented 2 years ago

As I wrote earlier in https://github.com/helloSystem/Menu/issues/65#issuecomment-1279977618 the clearing is on purpose only implemented when a user changes application, so one can browse the filtered application menu. (btw there is QMenu::ABoutToHide) Perhaps the clear could happen only when a search result action is triggered? And/or the QLineEdit could have a clear button https://doc.qt.io/qt-5/qlineedit.html#clearButtonEnabled-prop

probonopd commented 2 years ago
    connect(m_searchMenu,&QMenu::aboutToHide,this,[this]{
          searchLineEdit->clear();
          searchLineEdit->textChanged("");
    });

does the trick. But as you write, this essentially makes the filtering of the main (hoizontal) menu bar obsolete. I am not sure yet whether anyone will actually use the filtered main (hoizontal) menu bar, although it is an interesting idea.

Perhaps the clear could happen only when a search result action is triggered?

Yes, that'd be possible. Do you know where it would have to go for it to work like that?

And/or the QLineEdit could have a clear button

Something like this... image

Could be done in addition, but personally I am always for simple solutions... I never had to click that button on the Mac.

probonopd commented 2 years ago

This would be a small improvement:

    connect(qApp, &QApplication::focusWindowChanged,
            this, [this](QWindow *w) {
        searchLineEdit->clear();
        searchLineEdit->textChanged("");
    });

Actually I am surprised that we are getting focusWindowChanged events if the user moves the cursor from the Search menu to other menus, and not only if the focus goes away from the Menu application MainWindow as a whole. Apparently Qt thinks of a menu as a "window"?

So this seems to get the job done:

    connect(qApp, &QApplication::focusWindowChanged, this, [this](QWindow *w) {
        if (!w) {
            // Clean the search box if the user has left the Menu application altogether
            searchLineEdit->clear();
            searchLineEdit->textChanged("");
        }
    });

I am happy with this behavior now. You too @jsm222?