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 How to keep System tray icons

    Hi All,
    I have to keep System tray icon when i executed my application..below is the code i written its working but the icon is not visible.

    Qt Code:
    1. QIcon icon;
    2. icon.addPixmap(QPixmap(QString::fromUtf8(":/images/home.png")),
    3. QIcon::Normal, QIcon::Off);
    4.  
    5. tray.setIcon(QIcon( icon));//":/images/home.png"));
    6. tray.setContextMenu(&cmenu);
    7. connect(&tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
    8. this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
    9.  
    10.  
    11. void abc::trayActivated(QSystemTrayIcon::ActivationReason reason)
    12. {
    13. switch(reason)
    14. {
    15. case QSystemTrayIcon::Trigger:
    16. {
    17. if(isHidden()) show();
    18. else hide();
    19. break;
    20. }
    21. default: break;
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    plz can anyone give idea about this.........

    regards,
    mkkguru

  2. #2
    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

    Seems you have to create your QSystemTrayIcon on the heap!

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

    mkkguru (23rd February 2010)

  4. #3
    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

    For what i see you show the icon only on response of a QSystemTrayIcon::Trigger event but that reason is sended only when "The system tray entry was clicked" but that's impossible if you haven't already showed it up with show....

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

    mkkguru (23rd February 2010)

  6. #4
    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

    Is there any possiblility to show my icon at systemtray.........?plz give me idea regarding this..........

  7. #5
    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

    Quote Originally Posted by Lykurg View Post
    Seems you have to create your QSystemTrayIcon on the heap!
    How to create QSystemTrayIcon on the heap??plz give me some idea.

  8. #6
    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 mkkguru View Post
    How to create QSystemTrayIcon on the heap??plz give me some idea.
    show us all your relevant code! The part you posted is confusing and "wrong". On the heap I mean:
    Qt Code:
    1. class Foo {
    2. //...
    3. private:
    4. }
    5.  
    6. Foo:Foo() {
    7. //...
    8. tray = new QSystemTrayIcon(this);
    9. }
    To copy to clipboard, switch view to plain text mode 

  9. #7
    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

    just after

    Qt Code:
    1. connect(&tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
    2. this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
    To copy to clipboard, switch view to plain text mode 

    put

    Qt Code:
    1. tray.show()
    To copy to clipboard, switch view to plain text mode 

  10. #8
    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

    Quote Originally Posted by Corinzio View Post
    just after

    Qt Code:
    1. connect(&tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
    2. this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
    To copy to clipboard, switch view to plain text mode 

    put

    Qt Code:
    1. tray.show()
    To copy to clipboard, switch view to plain text mode 
    i did but it no use still the error is comming as below

    Qt Code:
    1. ................................
    2. QSystemTrayIcon::setVisible: No Icon set
    To copy to clipboard, switch view to plain text mode 

    so how to set icon to systemtray

  11. #9
    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.....

  12. #10
    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

  13. #11
    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.