trayicon

trayicon

SystemTrayIcon using KDE,QT

System Tray Icon ( Linux, Kde, Qt )

If you want to write an application which sits in the System tray of the window manager, which is really important if you dont' need much of interaction with the user.

The following are the steps for setting up your application window in the tray icon.

  1. include kapplication.h , include ksystray.h

  2. in .pro file INCLUDEPATH += /usr/include/kde ( or the dir where kde headers are present ) and LIBS += -lartsgui_kde ( the library for kde )

  3. Create instance of KSystemTray with your widget as parent

  4. call setPixmap( ) function of KSystemTray to set the icon to be seen in SysTray.

  5. use KApplication instead of QApplication.

How to do the above?

here is how you do it:

main.cpp

#include <kapplication.h>

#include <ksystemtray.h>

#include <kcmdlineargs.h>

#include <qpixmap.h>

#include "widget.h"

int main( int argc, char **argv )

{

//Use KApplication instead of QApplication

KApplication q( argc, argv, "hello test" );

myWidget *wid = new myWidget( );

//Create Instance of KSystemTray

KSystemTray *tray = new KSystemTray( wid, "tray icon" );

QPixmap tmp("someimage_22x22image");

tray->setPixmap( tmp );

q.setMainWidget( wid );

return q.exec( );

}

.pro file

######################################################################

# Automatically generated by qmake (1.07a) Tue Sep 21 02:06:14 2004

######################################################################

TEMPLATE = app

INCLUDEPATH += .

INCLUDEPATH += /usr/include/kde/

LIBS += -lartsgui_kde

# Input

HEADERS += widget.h

SOURCES += main.cpp widget.cpp

Note: The above is only the part of code not full Its' just to give you and idea of how to do it using Qt in Linux.