[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Inheritance not supported?
From:       Phil Thompson <phil () river-bank ! demon ! co ! uk>
Date:       2003-01-25 13:02:09
[Download RAW message or body]

On Thursday 23 January 2003 1:52 pm, marvelan L wrote:
> Hi,
>
> I'm trying to use my own subclassed QPixmap in a QComboBox. But it
> seems that the QComboBox.pixmap method just returns the base class
> and not my sub class!
>
> Does not PyQt support the use of subclassed Qt objects?

Yes it does.

> This seems like a bug in PyQt to me?!?

I think it's a feature of Qt and you would observe the same behaviour with the 
equivalent C++ code.

> An example... The following should print MyPixmap and not qt.QPixmap:
>
> from qt import *
> import sys
>
> class MyPixmap(QPixmap):
>
>     def __init__(self):
>         QPixmap.__init__(self)
>
> app = QApplication(sys.argv)
> main = QMainWindow()
> main.setGeometry(0,0,400,400)
> app.setMainWidget(main)
>
> combo = QComboBox(main)
> combo.insertItem( MyPixmap(), "One")
>
> mypixmap = combo.pixmap(0)
>
> print "MyPixmap?", mypixmap, mypixmap.__class__
>
> main.show()
> app.exec_loop()

I haven't dug into the implementation of QComboBox but I think it makes a copy 
of the QPixmap so QComboBox.pixmap() is actually returning a different 
instance.

An indication that this is the case is that your MyPixmap instance will get 
garbage collected after the call to QComboBox.insertItem() because you do not 
keep a reference to it. If a copy wasn't being made then the QPixmap returned 
by QComboBox.pixmap() would be garbage and likely to cause a segmentation 
fault at some point.

Phil

_______________________________________________
PyKDE mailing list    PyKDE@mats.gmd.de
http://mats.gmd.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic