On 5/14/07, <b class="gmail_sendername">Hans-Peter Jansen</b> <<a href="mailto:hpj@urpla.net">hpj@urpla.net</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Am Montag, 14. Mai 2007 09:56 schrieb Phil Thompson:<br>> On Sunday 13 May 2Hmm, shouldn't this code behave in the same way too, than:<br><br> void paintEvent(QPaintEvent* event)<br> {<br> QPainter p(this);
<br> QPen pn=p.pen();<br> pn.setWidth(2);<br><br>[found in qt3/doc/examples/progress/progress.cpp, line 85]007 4:18 pm, Hans-Peter Jansen wrote:<br>> > Hi Phil,<br>> ><br>> > while at PyQt3 issues, could you look into an issue with pens, when
<br>> > fetching them with pen() from a QPainter. When using a QPen() instance,<br>> > all is well, but modifying the fetched pen does not work (a pen with<br>> > default properties will be used, no matter what is set on it).
<br>><br>> In C++ pen() returns a const reference - and SIP doesn't support const<br>> except to cast it away. I don't know what the C++ compiler is supposed to<br>> do in those circumstances - but it looks like it is just discarding any
<br>> attempts to modify the const QPen.<br><br>Hmm, shouldn't this code behave in the same way too, than:<br><br> void paintEvent(QPaintEvent* event)<br> {<br> QPainter p(this);<br> QPen pn=p.pen
();<br> pn.setWidth(2);<br><br>[found in qt3/doc/examples/progress/progress.cpp, line 85]<br><br>> If SIP properly supported const then you would get an exception when you<br>> called setColor().<br>><br>> The solution is to make a non-const copy of the pen...
<br>><br>> p = QPainter(self)<br>> pn = QPen(p.pen())<br>> pn.setColor(Qt.red)<br>><br>> Phil<br><br>Ahh, I see. Thanks.<br><br>Mind throwing the attached progress.py into examples3? Apart from a bunch of
<br>fixes, a few different default settings and menu shortcuts it much more<br>resembles the current Qt version now (functional and visual wise).<br><br>Cheers,<br> Pete "Retro" Jansen<br></blockquote></div><br>
A bit off-topic, but the reason the C++ version you referenced works is because in C++ this will implicitly make a mutable copy of the const QPen object using QPen's copy constructor. In python, you apparently have to do that explicitly.
<br><br>Ingmar<br>