Results 1 to 18 of 18

Thread: Minimize to system tray

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2007
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Minimize to system tray

    That didn't help either
    I also tried accepting and/or ignoring events and also didn't work, the window is still not hidden from the taskbar and the client area not painted.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Minimize to system tray

    Qt Code:
    1. bool MyInstantMessenger::event (QEvent *e)
    2. {
    3. if(e->type() == QEvent::WindowStateChange)
    4. {
    5. //Now check to see if the window is minimised
    6. if (isMinimized())
    7. {
    8. hide ();
    9. }
    10. }
    11. return QDialog::event( e );
    12. }
    To copy to clipboard, switch view to plain text mode 
    ]

    Is this what you did?

    EDIT: This is what you need to do. You have to let QDialog handle the change event. You must not accept nor ignore the event. Just hide your window.

    regards
    Last edited by marcel; 17th April 2007 at 08:21.

  3. The following user says thank you to marcel for this useful post:

    aLiNuSh (17th April 2007)

  4. #3
    Join Date
    Mar 2007
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Minimize to system tray

    Quote Originally Posted by marcel View Post
    Qt Code:
    1. bool MyInstantMessenger::event (QEvent *e)
    2. {
    3. if(e->type() == QEvent::WindowStateChange)
    4. {
    5. //Now check to see if the window is minimised
    6. if (isMinimized())
    7. {
    8. e->accept ();
    9. hide ();
    10. return true;
    11. }
    12. }
    13. return QDialog::event( e );
    14. }
    To copy to clipboard, switch view to plain text mode 
    ]

    Is this what you did?
    Maybe... I tried so many different combinations I can't remember anymore.
    Anyways I tried it now and it does the same thing... when I push the minimize button the window minimizes to the taskbar and the taskbar "button for the window" disappears and appears again quickly, and then when I maximize it, the window shows on the screen but the client area is not painted. Obviously it has to be something with some of the events not being forwarded for default processing... i just don't know what I'm missing here...

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Minimize to system tray

    Could you show me the actual code? The one that you last tried

  6. #5
    Join Date
    Mar 2007
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Minimize to system tray

    I just closed Notepad++ and deleted the code... basically I've tried reimplementing changeEvent () or event () sometimes accepting or rejecting the events, sometimes returning true or false or QWidget::changeEvent ()/event() and other different combinations.
    I lost 4 hours on this stupid thing and still haven't got it working.

    Anyways thanks for the assistance and maybe when I'll feel masochist enough I'll retry it :P

    We're from the same country BTW

    LE: tried the edited one too.. same thing
    Last edited by aLiNuSh; 17th April 2007 at 09:13.

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

    Default Re: Minimize to system tray

    Quote Originally Posted by aLiNuSh View Post
    That didn't help either
    I also tried accepting and/or ignoring events and also didn't work, the window is still not hidden from the taskbar and the client area not painted.
    I faced the same problem.

    Anyone has a solution to these issues?

    Thanks in advance.

  8. #7
    Join Date
    Jun 2009
    Location
    Austria
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Minimize to system tray

    Hi !

    I also have the problem with the systrayicon and minimize
    so i try following ...

    Qt Code:
    1. // Overload original event-handler:
    2. bool MainWindow::event(QEvent *evt)
    3. {
    4. // Check if Window-State changed to minimize ...
    5. if(evt->type() == QEvent::WindowStateChange)
    6. {
    7. //Now check to see if the window is minimised
    8. if (isMinimized())
    9. {
    10. // Call the Hide Slot after 250ms
    11. // to prozess other events ....
    12. qApp->processEvents();
    13. QTimer::singleShot(250, this, SLOT(hide()));
    14. evt->ignore();
    15. }
    16. }
    17. // Call original-handler (in this case QMainWindow ...)
    18. return QMainWindow::event(evt);
    19. }
    To copy to clipboard, switch view to plain text mode 

    ... this work's on windows !

  9. #8
    Join Date
    Oct 2009
    Posts
    35
    Thanks
    12
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11

    Smile Re: Minimize to system tray

    Use the below code it might be helpful to you.......

    Qt Code:
    1. //System tray icon action context menu
    2.  
    3. minimizeAction = new QAction(tr("Mi&nimize"), this);
    4. connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
    5.  
    6. maximizeAction = new QAction(tr("Ma&ximize"), this);
    7. connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
    8.  
    9. restoreAction = new QAction(tr("&Restore"), this);
    10. connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
    11.  
    12. quitAction = new QAction(tr("&Quit"), this);
    13. connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    14.  
    15. //ToolbarAction(itemExit).icon(), ToolbarAction(itemExit).text(), parent);
    16. cmenu.addAction(tr("Show"), this, SLOT(show()));
    17. cmenu.addAction(tr("Hide"), this, SLOT(hide()));
    18. cmenu.addSeparator();
    19. cmenu.addAction(minimizeAction);
    20. cmenu.addAction(maximizeAction);
    21. cmenu.addAction(restoreAction);
    22. cmenu.addAction(quitAction);
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Red face A solution - Re: Minimize to system tray

    Hi, here is a solution, and I think it works quite well in my application:

    In the dialog's slot that connects with the activated() signal of the QSystemTrayIcon object, use the setParent() function as:
    Qt Code:
    1. void FtpDialog::sysTrayActivated(QSystemTrayIcon::ActivationReason reason)
    2. {
    3. if (reason == QSystemTrayIcon::Trigger){
    4. setParent(NULL, Qt::Window);
    5. showNormal();
    6. sysTrayIcon->hide();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    And in the dialog's event() function:

    Qt Code:
    1. bool FtpDialog::event(QEvent *e)
    2. {
    3. if (e->type() == QEvent::WindowStateChange) {
    4. if (isMinimized()) {
    5. setParent(tmp, Qt::SubWindow);
    6. sysTrayIcon->show();
    7. e->ignore();
    8. qDebug()<<"event() called";
    9. } else {
    10. e->accept();
    11. }
    12.  
    13. }
    14. return QDialog::event(e); // return with QDialog's event() call anyway.
    15. }
    To copy to clipboard, switch view to plain text mode 

    Here, 'tmp' is an empty QWidget serving as a provisional 'parent' of the dialog, so that the dialog can be hidden from task-bar when minimized. In fact, you can just pass NULL as the first argument for the 'parent' widget, but in this case probably the re-stored window would exhibit slightly different with the original window size.

Similar Threads

  1. Hide on Minimize
    By defunct in forum Qt Programming
    Replies: 9
    Last Post: 26th March 2009, 09:46
  2. Minimize to system tray
    By krivenok in forum Qt Programming
    Replies: 5
    Last Post: 13th January 2009, 04:34
  3. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  4. System title bar height
    By andynugent in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 16th October 2006, 15:57
  5. How to change system menu of window?
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2006, 15:19

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
  •  
Qt is a trademark of The Qt Company.