Results 1 to 9 of 9

Thread: Intercept minimize window event

  1. #1
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Intercept minimize window event

    Hi.

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

    First approach:

    Qt Code:
    1. protected:
    2. virtual void changeEvent(QEvent*);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void LineWatcherMain::changeEvent(QEvent* evt){
    2. if(evt->type()==QEvent::WindowStateChange&&isMinimized()){
    3. evt->ignore();
    4. hide();
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

    Second approach:

    Same declaration as above, but different implementation.

    Qt Code:
    1. void LineWatcherMain::changeEvent(QEvent* evt){
    2. if(evt->type()==QEvent::WindowStateChange&&isMinimized()){
    3. evt->ignore();
    4. hide();
    5. }else QMainWindow::changeEvent(evt);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Third approach:

    Qt Code:
    1. protected:
    2. virtual bool eventFilter(QObject*,QEvent*);
    To copy to clipboard, switch view to plain text mode 

    In constructor:
    Qt Code:
    1. installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 

    Implementation:
    Qt Code:
    1. bool LineWatcherMain::eventFilter(QObject* obj,QEvent* evt){
    2. if(evt->type()==QEvent::WindowStateChange&&isMinimized()){
    3. evt->ignore();
    4. hide();
    5. return true;
    6. }else return QMainWindow::eventFilter(obj,evt);
    7. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Intercept minimize window event

    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.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Intercept minimize window event

    Quote Originally Posted by axeljaeger View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Intercept minimize window event

    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.
    It's nice to be important but it's more important to be nice.

  5. #5
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Intercept minimize window event

    Quote Originally Posted by axeljaeger View Post
    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Intercept minimize window event

    So minimize and close should both do the same thing? Does this make sense at all? Why have two buttons for the same thing?
    It's nice to be important but it's more important to be nice.

  7. #7
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Intercept minimize window event

    Quote Originally Posted by axeljaeger View Post
    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

  8. #8
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Intercept minimize window event

    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.
    Last edited by axeljaeger; 16th October 2009 at 14:47.
    It's nice to be important but it's more important to be nice.

  9. The following user says thank you to axeljaeger for this useful post:

    vereteran (17th October 2009)

  10. #9
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Intercept minimize window event

    Quote Originally Posted by axeljaeger View Post
    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.

Similar Threads

  1. Replies: 2
    Last Post: 9th August 2009, 22:08
  2. Replies: 4
    Last Post: 19th February 2009, 11:10
  3. correct event for lose focus in a QGLWidget window
    By john_god in forum Qt Programming
    Replies: 4
    Last Post: 16th February 2009, 01:34
  4. Intercept ShowDesktop event
    By Lele in forum Qt Programming
    Replies: 4
    Last Post: 20th December 2007, 20:05
  5. Problem hiding main window on minimize
    By bpetty in forum Newbie
    Replies: 5
    Last Post: 18th September 2007, 17:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.