[PyQt] Bug ovverriding sizeHint

Giovanni Bajo rasky at develer.com
Fri Feb 22 16:59:37 GMT 2008


Hi,

consider this snippet:

=======================================================
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.
-- 
Giovanni Bajo



More information about the PyQt mailing list