[PyQt] [PyQt3] QPen issues

Phil Thompson phil at riverbankcomputing.co.uk
Mon May 14 08:56:28 BST 2007


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.

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


More information about the PyQt mailing list