[PyQt] Problem updating QLabel font

Phil Thompson phil at riverbankcomputing.co.uk
Mon Jan 7 15:09:27 GMT 2008


On Monday 07 January 2008, Arve Knudsen wrote:
> Hello
>
> I've run into what looks like a bug in PyQt. When changing the font of a
> QLabel at runtime, it doesn't update its appearance unless I call its
> update() method. I've verified that this problem doesn't occur when using
> Qt directly from C++. Even after calling update(), something isn't right
> however, as the containing QGridLayout isn't adjusted to account for the
> label's changed dimensions.
>
> The attached program showcases the problem. Uncomment line 20 to see the
> layout problem.

Change the first line of changeFont() to...

    f = QFont(self.__lab.font())

...so that it is closer to what C++ would do.

SIP doesn't enforce "const". I've been mulling over this for a while. SIP 
could enforce "const" so that the call to setBold() would raise an exception. 
The disadvantage is that existing apps may break - but, then again, they are 
broken anyway.

An alternative might be to automatically make a copy under the covers so that 
wrapped C++ instances are never const.

Phil


More information about the PyQt mailing list