[PyQt] Problem updating QLabel font

Arve Knudsen arve.knudsen at gmail.com
Mon Jan 7 15:56:40 GMT 2008


On 1/7/08, Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
>
> 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.


Ah, this semantic detail escaped me. The typical C++ way is to
say QFont f = label.font() . What I didn't notice however is that this makes
a copy of the returned reference.

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.
>

A soft warning (as opposed to an exception) is perhaps also a third
alterantive, so that the programmer knows he's doing something wrong?

Thanks,
Arve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080107/09b5c4c7/attachment.html


More information about the PyQt mailing list