Results 1 to 11 of 11

Thread: How to keep System tray icons

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    35
    Thanks
    12
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11

    Default Re: How to keep System tray icons

    I updated the code as follows still the error coming as QSystemTrayIcon::setVisible: No Icon set
    Qt Code:
    1. void foo ::createTrayIcon()
    2. {
    3. QIcon icon;
    4. icon = QIcon(QPixmap( ":/images/new.png" ) );
    5. tray = new QSystemTrayIcon(icon,this);
    6. tray->setContextMenu(cmenu);
    7. tray->setIcon(icon);
    8. tray->setVisible(true);
    9. setWindowIcon(icon);
    10. tray->show();
    11. connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
    12. this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
    13. }
    14.  
    15. void foo::iconActivated(QSystemTrayIcon::ActivationReason reason)
    16. {
    17.  
    18. switch (reason) {
    19. case QSystemTrayIcon::Trigger:
    20. tray->show();
    21. case QSystemTrayIcon::DoubleClick:
    22. break;
    23. case QSystemTrayIcon::MiddleClick:
    24. // showMessage();
    25. break;
    26. default:
    27. ;
    28. }
    To copy to clipboard, switch view to plain text mode 

    Plz give some idea regarding this.................thanks in advance.....

  2. #2
    Join Date
    Nov 2008
    Location
    Italy
    Posts
    16
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to keep System tray icons

    I think you should create the QIcon on the heap with new.
    In your code the QIcon icon goes out of scope when the foo::createTrayIcon() functions ends...

    i'm not sure....
    sorry

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to keep System tray icons

    Quote Originally Posted by Corinzio View Post
    I think you should create the QIcon on the heap with new.
    In your code the QIcon icon goes out of scope when the foo::createTrayIcon() functions ends...

    i'm not sure....
    sorry
    No better create it on the stack. It is copied to the system tray icon instance. Try that code in your main window:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. // BEGIN HERE
    8. QIcon icon = QIcon("/data/misc/nuvola/32x32/apps/kcmsystem.png");
    9. QSystemTrayIcon *tray = new QSystemTrayIcon(icon, this);
    10. tray->show();
    11. // END HERE
    12. }
    To copy to clipboard, switch view to plain text mode 
    and see if it works. Works fine on my machine. And make sure your resource system works fine and your png is actually found.

Similar Threads

  1. Minimize to system tray
    By aLiNuSh in forum Newbie
    Replies: 17
    Last Post: 4th March 2010, 12:51
  2. how to use System Tray Icons in QToolBar
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2009, 15:52
  3. Minimize to system tray
    By krivenok in forum Qt Programming
    Replies: 5
    Last Post: 13th January 2009, 04:34
  4. Transparency problems with system tray in Windows
    By lliehu in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2007, 15:37
  5. system tray problem
    By vvdounai in forum Qt Programming
    Replies: 5
    Last Post: 14th November 2007, 08:25

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.