Results 1 to 4 of 4

Thread: Windws Taskbar Entry

  1. #1
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy Windws Taskbar Entry

    Hi All,

    I have tried everything I can find in this forum and on the web to get this to work, and nothing seems to solve my problem.

    I have a program made with QT 4.3, which should hide to the tray icon.

    When I hide it using the tray icon, it works fine, even on Windows the task-bar entry goes away, leaving just the icon tray:

    Qt Code:
    1. void vfalerter::iconClicked( QSystemTrayIcon::ActivationReason reason )
    2. {
    3.  
    4. if( reason == QSystemTrayIcon::Trigger ) {
    5. // The icon in the tray was clicked
    6. if(this->isVisible())
    7. this->hide();
    8. else
    9. this->showNormal();
    10. }
    11. else if( reason == QSystemTrayIcon::MiddleClick ) {
    12. // The icon was middle-clicked
    13. showPopup( statusText, 1 );
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    That part works great. But when i try and capture the Minimize event from the main window, it leaves the task bar entry there.

    Qt Code:
    1. bool vfalerter::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if( event->type() == QEvent::Hide ) {
    4. // Window was minimized
    5. this->hide();
    6. return false;
    7. }
    8. else if( event->type() == QEvent::Close) {
    9. // We are exiting
    10. trayicon->hide();
    11.  
    12. // Delete any popups
    13. while( popups.count() )
    14. delPopup( popups[0] );
    15. return false;
    16. }
    17. else if( event->type() == QEvent::Show) {
    18. this->show();
    19. return false;
    20. }
    21. else {
    22. // Other events should be passed back to the main window
    23. return QObject::eventFilter(obj, event);
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    The only way I have been able to make the taskbar entry go away in Windows from the minimize button is by adding:

    Qt Code:
    1. setWindowFlags( Qt::SubWindow );
    To copy to clipboard, switch view to plain text mode 

    ..to the hide function, but then the window never comes back the way it was when I restore it, and I'm pretty sure that wouldn't be the right way of doing it.

    The whole things works as expected in KDE, its just Windows that has a problem.

    Anyone got any ideas?

  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: Windws Taskbar Entry

    When you minimize, you return false in the event filter. This is a problem since the "other" things won't be performed by the subclass for this event. By "other" I mean the stuff related to minimizing to tray and setting the appropriate flags for the window to disappear from task bar.

    I suggest returning the base class version of eventFilter instead of false.

    Regards

  3. #3
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Windws Taskbar Entry

    I think I already tried that, didn't seem to help.

    I don't understand why the hide in the IconTray function works fine, but the one in the Event does not :-(

  4. #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: Windws Taskbar Entry

    The event for a state change( e.g. minimize) is QWindowStateChangeEvent.

    So I think that your mistake is to call hide() for a hide event. Well, a call to hide() triggered that event in the first place.

    So you should handle this event instead,, and hide it there. Also you should ignore the event in this case, because you don't actually want to minimize the window. You just want to use the minimize button for hiding the window.

    Please refer to the System Tray example in the Qt Demos for a full example.
    Here's a small snippet:
    Qt Code:
    1. void Window::closeEvent(QCloseEvent *event)
    2. {
    3. if (trayIcon->isVisible()) {
    4. QMessageBox::information(this, tr("Systray"),
    5. tr("The program will keep running in the "
    6. "system tray. To terminate the program, "
    7. "choose <b>Quit</b> in the context menu "
    8. "of the system tray entry."));
    9. hide();
    10. event->ignore();
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    This is how they implemented it. They hide the task bar button at close. The only difference is that you hide it at minimize, so the implementation should be the same.

    Regards.

Similar Threads

  1. Parentless window with no taskbar entry
    By durbrak in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2006, 14:46

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.