[PyKDE] PyKDE application icon

Jim Bublitz jbublitz at nwinternet.com
Mon Feb 28 22:24:56 GMT 2005

On Monday 28 February 2005 11:11, Akos Polster wrote:
> Hi,
> as a newbie to PyKDE and KDE in general, I'm trying to set the icon for
> an application with no luck (the default icon remains displayed). See
> the code below. What's wrong with it?

I'm not sure if you can set the application icon in KDE without getting into 
accessing window manager functions, which is possible from PyKDE (haven't 
tried it in this case though). The areas where the icon appears belong to the 
window manager (except you can set the caption). setIcon will work for Qt 
apps, however.

The easiest way to set the icon (to the "kmail" icon in this case) is to 

 about = KAboutData ("icon", "icon", "1.0", "icon", \
     KAboutData.License_GPL, "")


 about = KAboutData ("kmail", "icon", "1.0", "icon", \
     KAboutData.License_GPL, "")

If you want to use something other than the "kmail" icon (which I imagine you 
do), you'll need to install the icon somewhere in the kde3/share/icons 
hierarchy. I'm not sure what paths the window manager uses to search for 
icons - I think I'd try icons/hicolor/*/apps first (* is the various icon 
size subdirs). icons/default.kde is a symlink on my installation, and points 
to the default theme.

Things like calling "setTopWidget" after creating the main window don't seem 
to have any effect. Putting the icon in the same directory as the Python 
executable doesn't seem to work either.

There may be a way to use KStandardDirs to set an alternate path as well - 
haven't looked into that. Check the KDE docs for that.

This is a function of how KDE is designed.


> ...........
> import sys
> from kdecore import KApplication, KAboutData, KIcon, KIconLoader, \
>       KCmdLineArgs
> from kdeui import KMainWindow, KMessageBox
> class MainWin(KMainWindow):
>     def __init__ (self, *args):
>         apply(KMainWindow.__init__, (self,) + args)
>         self.setIcon(KIconLoader().loadIcon("kmail", KIcon.Desktop))
> about = KAboutData ("icon", "icon", "1.0", "icon", \
>     KAboutData.License_GPL, "")
> KCmdLineArgs.init(sys.argv, about)
> app = KApplication()
> mainWindow = MainWin(None, "main window")
> mainWindow.show()
> app.exec_loop()

More information about the PyQt mailing list