Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: Tray icon & taskbar app button hide

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Tray icon & taskbar app button hide

    I want to have my application to be maximized while being shown at the systray in Windows. I tried this (following the QT Demos):
    Qt Code:
    1. private:
    2. QSystemTrayIcon *trayIcon;
    3. ..............{}.................
    4. trayIcon->setVisible(true);
    5. trayIcon->show();
    To copy to clipboard, switch view to plain text mode 
    But that only crashes the application. And I'm clueless. I also needed to have the app's taskbar button to hide itself. I did some searching but didnt find anything up-to-date. Any help is welcome and thanked.

  2. #2
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Tray icon & taskbar app button hide

    For example:

    app.h
    Qt Code:
    1. private:
    2. QSystemTrayIcon *trayIcon;
    3. QMenu *trayIconMenu;
    4.  
    5. QAction *minimizeAction;
    6. QAction *maximizeAction;
    7. QAction *restoreAction;
    8. QAction *quitAction;
    9.  
    10. void createActions();
    11. void createTrayIcon();
    12. void showMessage();
    To copy to clipboard, switch view to plain text mode 

    app.cpp
    Qt Code:
    1. app::app(QWidget *parent, Qt::WFlags flags)
    2. : QDialog(parent, flags)
    3. {
    4. ...
    5. createActions();
    6. createTrayIcon();
    7. trayIcon->setIcon(QIcon(QString::fromUtf8(":/app/Resources/Add.png")));
    8. trayIcon->show();
    9. connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
    10. this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
    11. ...
    12. }
    13.  
    14. void app::createActions()
    15. {
    16. minimizeAction = new QAction(tr("Mi&nimize"), this);
    17. connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
    18.  
    19. restoreAction = new QAction(tr("&Restore"), this);
    20. connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
    21.  
    22. quitAction = new QAction(tr("&Quit"), this);
    23. connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    24. }
    25.  
    26. void HSM::createTrayIcon()
    27. {
    28. trayIconMenu = new QMenu(this);
    29. trayIconMenu->addAction(minimizeAction);
    30. trayIconMenu->addAction(restoreAction);
    31. trayIconMenu->addSeparator();
    32. trayIconMenu->addAction(quitAction);
    33.  
    34. trayIcon = new QSystemTrayIcon(this);
    35. trayIcon->setContextMenu(trayIconMenu);
    36. trayIcon->setToolTip(tr("My app"));
    37. }
    38.  
    39. void app::createActions()
    40. {
    41. minimizeAction = new QAction(tr("Mi&nimize"), this);
    42. connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
    43.  
    44. restoreAction = new QAction(tr("&Restore"), this);
    45. connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
    46.  
    47. quitAction = new QAction(tr("&Quit"), this);
    48. connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    49. }
    50.  
    51. void app::showMessage()
    52. {
    53. QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon();
    54. trayIcon->showMessage(tr("My app"), tr("Some msg"), icon, 100);
    55. }
    56.  
    57. void app::iconActivated(QSystemTrayIcon::ActivationReason reason)
    58. {
    59. switch (reason)
    60. {
    61. case QSystemTrayIcon::Trigger:
    62. show();
    63. break;
    64. case QSystemTrayIcon::DoubleClick:
    65. show();
    66. break;
    67. case QSystemTrayIcon::MiddleClick:
    68. showMessage();
    69. break;
    70. default:
    71. ;
    72. }
    73. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Tray icon & taskbar app button hide

    Thanks! The tray icon is working really great. And that helped me understand QT a little bit more.

    And now...
    How do I hide its taskbar button?
    Attached Images Attached Images

  4. #4
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Tray icon & taskbar app button hide

    Anyone?....

  5. #5
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Tray icon & taskbar app button hide

    you can try like how I did it.

    Qt Code:
    1. void
    2. MainWindow::closeEvent(QCloseEvent *event) {
    3. if (Settings::enableSystemTray()) {
    4. if (Settings::minimizeToTrayOnClose()) {
    5. hide();
    6. event->ignore();
    7. }
    8. } else {
    9. QMainWindow::closeEvent(event);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  6. #6
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Tray icon & taskbar app button hide

    Can you explain what that does? And how to call it(send an event)

  7. #7
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Tray icon & taskbar app button hide

    closeEvent is called when the underlaying window system wants to close the main window. On windows by Alt-F4 or the close button.
    If enabled in the program's settings, you would provide the main window to be closed at all, but only be minimized to the tray.

  8. #8
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Tray icon & taskbar app button hide

    Oh... so it hides the window but doesnt close it... (what was I thinking...) but thats not what I need..
    I want my window to be shown, but remove the taskbar button.

  9. #9
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Tray icon & taskbar app button hide

    Maybe something like

    Qt Code:
    1. void
    2. MainWindow::showEvent(QShowEvent *event) {
    3. trayIcon->hide();
    4. QMainWindow::showEvent(event);
    5. }
    6. }
    7. void
    8. MainWindow::hideEvent(QHideEvent *event) {
    9. trayIcon->show();
    10. QMainWindow::hideEvent(event);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    (Assumed, neither tested nor knowed)

  10. #10
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Tray icon & taskbar app button hide

    Ok, will take a look at it

  11. #11
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Tray icon & taskbar app button hide

    That's not it. I dont want to hide the trayIcon. I want to hide the taskbar button.

  12. #12
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Tray icon & taskbar app button hide

    As the taskbar content is managed by the explorer.exe, this is something deep inside of your Vista...

    I believe there was something that the taskbar entry was not shown when the main window of the app had no frame
    Qt Code:
    1. setWindowFlags(Qt::FramelessWindowHint);
    To copy to clipboard, switch view to plain text mode 

    Another approach is shown on Codeguru. This example uses the MFC, but also explains what has to be done.

  13. #13
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Tray icon & taskbar app button hide

    mine is already set to Qt::FramelessWindowHint, doesnt change it. So I guess the solution is OS dependant.

  14. #14
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Tray icon & taskbar app button hide

    I've never seen any explorer.exe on my system, so... yes Indeed, I think it is window manager dependent.

  15. #15
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tray icon & taskbar app button hide

    here is how to hide the taskbar button, it was already explained to you in one of the earlier posts:

    Qt Code:
    1. void mymainwindow::closeEvent(QCloseEvent *event) {
    2. hide();
    3. event->ignore();
    4. }
    To copy to clipboard, switch view to plain text mode 

    notice that you'll have to subclass QMainWindow, here mymainwindow is subclass of QMainWindow..if you have any other questions, go through this thread again, your problem has already been solved.

  16. #16
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tray icon & taskbar app button hide

    Quote Originally Posted by auba View Post
    I've never seen any explorer.exe on my system, so... yes Indeed, I think it is window manager dependent.
    explorer.exe is always running on your windows system..killing that process removes your whole taskbar..check your task manager, you'll find explorer.exe staring at you like deer in headlights.

  17. #17
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Tray icon & taskbar app button hide

    I do not run windows at all as I have to work - not to play. I only use Vista to start my games but thats OT

  18. #18
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Red face Re: Tray icon & taskbar app button hide

    Quote Originally Posted by talk2amulya View Post
    here is how to hide the taskbar button, it was already explained to you in one of the earlier posts:

    Qt Code:
    1. void mymainwindow::closeEvent(QCloseEvent *event) {
    2. hide();
    3. event->ignore();
    4. }
    To copy to clipboard, switch view to plain text mode 

    notice that you'll have to subclass QMainWindow, here mymainwindow is subclass of QMainWindow..if you have any other questions, go through this thread again, your problem has already been solved.
    But doesnt that only hide my window? And if that really is the solution how do I call closeEvent()? I tried several ways but I really didnt get it. I need the taskbar button to be always hidden. I'm really lost here...

  19. #19
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tray icon & taskbar app button hide

    ok, so normally the way it works is when you have your window maximised, you dont have any tray icon..when you close the window, the taskbar button disappears and tray icon appears..then you double click the tray icon or choose maximise from its context menu, and the window appears and taskbar button appears..isnt that how you want it? if you do, close event would be called when you click close icon of window..or you can call it yourself if you want your application to start minimized..remember that when window is shown, taskbar button would always be there, there is no way to avoid that and i dont understand why anyone would even want that..you can use showEvent, hideEvent, closeEvent as mentioned in the posts..closeEvent code that i posted earlier would close your window and remove the taskbar button, right then you have to show the tray icon in tray, add that code..further, you can use the code posted by Fastman to work out the context menu of the tray icon..and you have your job done.

  20. #20
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Tray icon & taskbar app button hide

    A image is worth many words.This is what I need:

    From this:


    Note the taskbar button.

    To this:


    Note no taskbar button.
    Attached Images Attached Images

Similar Threads

  1. Hide QMainWindow without removing taskbar icon?
    By bigchiller in forum Qt Programming
    Replies: 5
    Last Post: 15th March 2009, 23:54
  2. How to write some text next to the system tray icon?
    By alex chpenst in forum Qt Programming
    Replies: 3
    Last Post: 5th September 2008, 09:43
  3. hide from taskbar but show to ALT-TAB
    By musikit in forum Qt Programming
    Replies: 0
    Last Post: 15th August 2008, 17:14
  4. button with backgr and icon using stylesheets
    By s_p_t10 in forum Qt Programming
    Replies: 0
    Last Post: 7th May 2008, 21:19
  5. Hide taskbar button
    By JeanC in forum Qt Programming
    Replies: 9
    Last Post: 12th March 2008, 10:59

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.