[PyKDE] Application icon
Jim Bublitz
jbublitz at nwinternet.com
Wed Nov 26 09:18:00 GMT 2003
On Tuesday November 25 2003 17:17, Tom Badran wrote:
> Whats the proper way of loading the application specific icon
> so that it will be found even without installing it to the
> share/icons/whatever directories? I have it in my source tree
> but i don't know how to tell the KIconLoader it should be
> looking there. Also, is there a way to tell the application as
> a whole that that particular icon is the main one, rather than
> loading it in the specific places it is needed?
------------------------------
import os.path
from kdecore import KApplication
from kdeui import KMainWindow
from qt import QPixmap
class MainWindow (KMainWindow):
def init (self, <args>):
KMainWindow.__init__ (<args>)
iconPath = somePath
self.setIcon (QPixmap (os.path.join (iconPath,
"appIcon.png")))
...
<other stuff>
app = KApplication (<args>)
mw = MainWindow (<args>)
<more stuff>
------------------------------
"setIcon" is a QWidget member - not exactly where you'd expect to
find it. Works for PyQt or PyKDE, not sure if it's "proper". In
Qt I think you'd also need to call "setMainWidget" after
instantiating "mw". Since "setIcon" is a QWidget method, it
should work for any type of top level widget, not just the main
window class types.
In the case of the application icon, I don't think KIconLoader
offers any advantages. For icons used within the app, it does
caching and probably improves performance a little. You can
probably get KIconLoader to use an arbitrary path to your icons
if you tell KStandardDirs about it (KStandardDirs.addResourceDir
method). You could also do that for your app icon. Directories
are added at the end of the KStandardDirs path, so icon
filenames should be unique.
KToolbar, for example, has insertButton methods that work with
KIconLoader or an arbitrary QPixmap, so either method would work
there. The PyQt alternative for icons is QIconSet.
Jim
More information about the PyQt
mailing list