[PyQt] [PyQt3] QPen issues

Hans-Peter Jansen hpj at urpla.net
Mon May 14 14:14:57 BST 2007


Am Montag, 14. Mai 2007 09:56 schrieb Phil Thompson:
> On Sunday 13 May 2007 4:18 pm, Hans-Peter Jansen wrote:
> > Hi Phil,
> >
> > while at PyQt3 issues, could you look into an issue with pens, when
> > fetching them with pen() from a QPainter. When using a QPen() instance,
> > all is well, but modifying the fetched pen does not work (a pen with
> > default properties will be used, no matter what is set on it).
>
> In C++ pen() returns a const reference - and SIP doesn't support const
> except to cast it away. I don't know what the C++ compiler is supposed to
> do in those circumstances - but it looks like it is just discarding any
> attempts to modify the const QPen.

Hmm, shouldn't this code behave in the same way too, than:

    void paintEvent(QPaintEvent* event)
    {
        QPainter p(this);
        QPen pn=p.pen();
        pn.setWidth(2);

[found in qt3/doc/examples/progress/progress.cpp, line 85]

> If SIP properly supported const then you would get an exception when you
> called setColor().
>
> The solution is to make a non-const copy of the pen...
>
>         p = QPainter(self)
>         pn = QPen(p.pen())
>         pn.setColor(Qt.red)
>
> Phil

Ahh, I see. Thanks.

Mind throwing the attached progress.py into examples3? Apart from a bunch of 
fixes, a few different default settings and menu shortcuts it much more 
resembles the current Qt version now (functional and visual wise). 

Cheers,
  Pete "Retro" Jansen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: progress.py
Type: application/x-python
Size: 9775 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20070514/7e7f7b60/progress.bin


More information about the PyQt mailing list