PDA

View Full Version : Intercept minimize window event



vereteran
15th October 2009, 11:25
Hi.

I want my main window to hide on mimization event.
Googling around gave me this ideas:

First approach:


protected:
virtual void changeEvent(QEvent*);


void LineWatcherMain::changeEvent(QEvent* evt){
if(evt->type()==QEvent::WindowStateChange&&isMinimized()){
evt->ignore();
hide();
}
}


Second approach:

Same declaration as above, but different implementation.


void LineWatcherMain::changeEvent(QEvent* evt){
if(evt->type()==QEvent::WindowStateChange&&isMinimized()){
evt->ignore();
hide();
}else QMainWindow::changeEvent(evt);
}

Third approach:


protected:
virtual bool eventFilter(QObject*,QEvent*);

In constructor:

installEventFilter(this);

Implementation:

bool LineWatcherMain::eventFilter(QObject* obj,QEvent* evt){
if(evt->type()==QEvent::WindowStateChange&&isMinimized()){
evt->ignore();
hide();
return true;
}else return QMainWindow::eventFilter(obj,evt);
}

All of them got 1 bug: window hide()'s, but when I'm doing show() it is mimized and even
if it was maximized it appears as normal.

What am I doing from?

Thank you.

axeljaeger
15th October 2009, 11:39
I think whether your windows is hidden or minimized is two different flags. Try to maximize it when you manually show it because you also manually hide it when it was minimized.

vereteran
15th October 2009, 11:51
I think whether your windows is hidden or minimized is two different flags. Try to maximize it when you manually show it because you also manually hide it when it was minimized.

The problem is I want to totally ignore mimization event and hide window.
As I understand show() and hide() are working with window visibility and don't influent on
minimized/maximized state.

As I see this: find some top level event processor which gets called when event just
arrived, not when it was processed by some parts (eventFilter and event are able to get window state from isMinized() so minimization is already applied as I understand) and
override it so it would hide() window and ignore() event byitself.

axeljaeger
15th October 2009, 11:55
Then you will have to fight against the window manager. What is exactly what you want to archive? Because for me it sounds like you want to do something that will violate the HIG of any plattform.

vereteran
15th October 2009, 12:13
Then you will have to fight against the window manager. What is exactly what you want to archive? Because for me it sounds like you want to do something that will violate the HIG of any plattform.

What I have: a program which has a tray icon. Icon clicked and main window's visibility is toggled. When user tries to close or minimize main window with window manager's close and minimize buttons main window is simply hiding.

axeljaeger
15th October 2009, 12:14
So minimize and close should both do the same thing? Does this make sense at all? Why have two buttons for the same thing?

vereteran
15th October 2009, 12:20
So minimize and close should both do the same thing? Does this make sense at all? Why have two buttons for the same thing?

I think it's correct to give user usual window control buttons. Event if they're doing a bit different things :)

axeljaeger
16th October 2009, 14:33
I think you are wrong, but I am not in the position to influence your software.

But because the behaviour of the close button is not meant to be changed by you, there is no API in Qt to do so and hopefully, there will never be one. Be prepared to implement this on every plattform again and that it might not work on some plattforms at all.

I think your motivation is to not clutter the user's taskbar but to somehow minimize to the system try. If this is true, remember that the user can forbid applications to put an application in the system tray at least on windows 7. More and more drivers put their icons in their and I have seen windows installations where half of the screen width was taken by the system tray. Think whether your application shall be side by side by all those hated things next to the clock.

vereteran
17th October 2009, 06:33
I think you are wrong, but I am not in the position to influence your software.

But because the behaviour of the close button is not meant to be changed by you, there is no API in Qt to do so and hopefully, there will never be one. Be prepared to implement this on every plattform again and that it might not work on some plattforms at all.

I think your motivation is to not clutter the user's taskbar but to somehow minimize to the system try. If this is true, remember that the user can forbid applications to put an application in the system tray at least on windows 7. More and more drivers put their icons in their and I have seen windows installations where half of the screen width was taken by the system tray. Think whether your application shall be side by side by all those hated things next to the clock.

I think you're right. And I don't want implement this for every platform/window manager.