[PyQt] Re: Bug ovverriding sizeHint

Giovanni Bajo rasky at develer.com
Mon Feb 25 09:57:42 GMT 2008


On 2/25/2008 10:29 AM, Phil Thompson wrote:

>> =======================================================
>> from PyQt4.Qt import *
>> app = QApplication([])
>> w = QWidget()
>> L = QVBoxLayout(w)
>> L.addWidget(QLabel("ciao", w))
>>
>> called_class = []
>> class MyScrollArea(QScrollArea):
>>      def sizeHint(self):
>>          called_class.append(1)
>>          return QSize(100,100)
>>
>> called_func = []
>> def mySizeHint(*args):
>>      called_func.append(1)
>>      return QSize(100,100)
>>
>> sv = MyScrollArea(w)
>> sv.sizeHint = mySizeHint    # the trick!
>>
>> L.addWidget(sv)
>> L.activate()
>> assert not called_class
>> assert called_func
>> =======================================================
>> Traceback (most recent call last):
>>    File "sizehint.py", line 24, in ?
>>      assert called_func
>> AssertionError
>>
>> My understanding is that the function "mySizeHint()" should be called
>> while calculating the size, as it was overridden. What happens is that,
>> misteriously, *neither* sizeHint() function is called.
>>
>> Of course, if you comment the marked line, the overridden method is
>> called, as expected.
> 
> SIP is looking for a method to invoke - not just a callable. See the 
> implementation of sip_api_is_py_method() in siplib.c.

I'm not sure I understand -- the comment seems to hint at a performance 
problem with PyCallable_Check. Besides the performance, would that work?
-- 
Giovanni Bajo



More information about the PyQt mailing list