Results 1 to 10 of 10

Thread: Hide on Minimize

  1. #1
    Join Date
    Jan 2006
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Hide on Minimize

    Hello,

    I have a Windows application that places an icon in the System Tray (modified the old trayicon example to work under Qt4). My question is; When I minimize my application, I want to remove it from the taskbar. I couldn't figure out how to do this using the changeEvent or hideEvent (I think because it's a spontaneous event). To solve this, I ended up having to reimplement the winEvent function as such:
    Qt Code:
    1. bool winEvent( MSG *m, long *result )
    2. {
    3. if ( mintotray )
    4. {
    5. switch ( m->message )
    6. {
    7. case WM_SIZE:
    8. {
    9. if ( m->wParam == SIZE_MINIMIZED )
    10. {
    11. ShowWindow(winId(), SW_HIDE);
    12. return true;
    13. }
    14. }
    15. break;
    16. default:
    17. break;
    18. }
    19. }
    20.  
    21. return QWidget::winEvent(m, result);
    22. }
    To copy to clipboard, switch view to plain text mode 

    Is there a cleaner way to do this using Qt events?

    Thanks in advance,
    -d

  2. #2
    Join Date
    Jan 2006
    Posts
    369
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide on Minimize

    IMHO you should ovveride this function on your QWindow:

    Qt Code:
    1. bool QWidget::winEvent ( MSG * message, long * result ) [virtual protected]
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide on Minimize

    Quote Originally Posted by elcuco
    IMHO you should ovveride this function on your QWindow:

    Qt Code:
    1. bool QWidget::winEvent ( MSG * message, long * result ) [virtual protected]
    To copy to clipboard, switch view to plain text mode 
    I did, I just didn't include the "ClassName::" to winEvent in the original post.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide on Minimize

    Try this (it's from an old thread on Qt Forum):
    by the way i've solved, i've found an old thread here in the forum.
    A good solution is

    bool MonitorUI::event(QEvent * e )
    {
    if (e->type()==QEvent::ShowMinimized )
    {
    hide();
    return true;
    }
    else
    return QMainWindow::event(e);
    }


    thanks Angelo

  5. The following user says thank you to jacek for this useful post:

    WinchellChung (3rd July 2007)

  6. #5
    Join Date
    Jan 2006
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide on Minimize

    Quote Originally Posted by jacek
    Try this (it's from an old thread on Qt Forum):
    That doesn't work. In Qt4, there is no ShowMinimized event. From what I can tell, by the time Qt4 gets the minimized event, the window has already been iconified. You can't stop it from happening (unless reimplementing winEvent, which I think is ugly).

    Does anyone know a way to trap spontaneous events before they happen?
    Last edited by defunct; 19th January 2006 at 20:30.

  7. #6
    Join Date
    Jan 2006
    Location
    Boston, MA
    Posts
    40
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Hide on Minimize

    Defunc: Can you show plz your modified trayicon example for Qt4 ?

  8. #7

    Default Re: Hide on Minimize

    I just tried the code in the original post and it worked with QT v4.1.3.

  9. #8
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hide on Minimize

    Quote Originally Posted by jacek View Post
    Try this (it's from an old thread on Qt Forum):
    Hi,

    Thanks for the suggestion. But, it DO NOT work on Qt 4.4.3 now.

    Anyone has ideas how can I hide to system tray when user click minimize or red 'x' on the upper right buttons?

    Thanks in advance.
    Last edited by sheeeng; 13th January 2009 at 06:34.

  10. #9
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: Hide on Minimize

    Hello,

    Sorry for resurrecting this thread but I am trying to achieve the same thing than the original poster, trying to hide my application when the "Minimize" icon is clicked or the "Minimize" option of the window menu (the one at the upper left corner of the windows in Windows Xp) is selected.

    I have tried all the suggested options (including some in other threads) without success, has anyone achieved this?

    Thank you!

  11. #10
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide on Minimize

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

    Good luck.

  12. The following user says thank you to The Storm for this useful post:

    araglin (30th March 2009)

Similar Threads

  1. Replies: 10
    Last Post: 20th April 2015, 22:24
  2. Minimize to system tray
    By aLiNuSh in forum Newbie
    Replies: 17
    Last Post: 4th March 2010, 12:51
  3. unable to hide combobox or spinbox in toolbar
    By Sandip in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2008, 11:52
  4. Problem hiding main window on minimize
    By bpetty in forum Newbie
    Replies: 5
    Last Post: 18th September 2007, 17:41
  5. model/view, can't hide row/col
    By grellsworth in forum Qt Programming
    Replies: 7
    Last Post: 17th September 2007, 14:21

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.