[PyKDE] QIconFactory

Fredrik Juhlin laz at strakt.com
Mon Sep 1 16:13:00 BST 2003


Hi,

I'm struggling to understand how to use QIconFactory. I can't seem to 
get createPixmap() in my subclassed QIconFactory called in a situation 
where, as far as I understand the docs, it should be called. Below is 
some sample code that demonstrates my problem.

Have I misunderstood how to use QIconFactory (of perhaps QIconSet?) or 
does the problem lie deeper (i.e., in PyQt)?

Any help would be much appreciated!

//Fredrik

---- test.py ----
import qt
import sys

class MyIconFactory(qt.QIconFactory):
     """
     My own QIconFactory. Always gives a null QPixmap.
     """
     def __init__(self):
         qt.QIconFactory.__init__(self)

     def createPixmap(self, iconset, size, mode, state):
         print 'in createPixmap()' # Never gets here
         return qt.QPixmap()

app = qt.QApplication(sys.argv)
mw = qt.QLabel(None)
app.setMainWidget(mw)

# Create an empty QIconSet and install my own brand of icon factory.
# This should ensure that QIconSet uses my createPixmap().
ic = qt.QIconSet()
ic.installIconFactory(MyIconFactory())

mw.setPixmap(ic.pixmap())
mw.show()

app.exec_loop()




More information about the PyQt mailing list