[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] return value from QGraphicsItem::itemChange is not handled properly.
From: Yann Le Hir <yann.le-hir () arteris ! com>
Date: 2013-08-29 14:58:07
Message-ID: 89804fa2fa934e38bd9878b4b6923b18 () BN1PR05MB140 ! namprd05 ! prod ! outlook ! com
[Download RAW message or body]
Hi,
I'm having an issue with QGraphicsItem::itemChange.
Here is the test program :
import PyQt5.Qt as qt
class Node( qt.QGraphicsRectItem ) :
def __init__( self , sector ) :
super( Node , self ).__init__( sector )
def itemChange( self , change , v ) :
res = super( Node , self ).itemChange( change , v )
print "itemChange return value : ",res
return res
b = qt.QGraphicsLineItem()
c = qt.QGraphicsLineItem()
a = Node(b)
print a.parentItem(),b
a.setParentItem(c)
print a.parentItem(), c
I get this output :
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x8f9f194> \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x8f9f194> itemChange return value : \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x8f9f1dc> itemChange return value : \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x8f9f1dc> None \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x8f9f1dc>
If I remove itemChange, I get this output :
<PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e6814c> \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e6814c> \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e68194> \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e68194>
I'm using PyQt-5.0, Sip 4.14.7 and Qt 5.1.0
I tried with PyQt-5.0.1, sip 4.15.1 and Qt 5.1.0 without change.
I digged into this, basically when setParentItem is called itemChange is called on \
this item and use the return value of itemChange to set the parent. In C itemChange \
returns a QVariant, which must be casted as a QGraphicsItem to be set as a parent. \
This took me to the Chimera::parse_py_type function. Apparently, someone (QT?) \
registers QGraphicsItem as a QMetaType, but not QGraphicsLineItem.
If I replace :
_metatype = QMetaType::type(_name.constData());
By :
if(strcmp(_name.constData(),"QGraphicsLineItem*")==0)
_metatype = QMetaType::type("QGraphicsItem*");
else
_metatype = QMetaType::type(_name.constData());
(I know how bad this is, but it's for demonstration purpose.)
The output of the test program is then :
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba194> \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba194> itemChange return value : \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba1dc> itemChange return value : \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba1dc> \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba1dc> \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba1dc>
Any ideas on how to fix this properly ?
Regards,
Yann.
[Attachment #3 (text/html)]
<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="FR" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">I’m having an issue with \
QGraphicsItem::itemChange.<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><o:p> </o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">Here is the test program :<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p> <p \
class="MsoNormal">import PyQt5.Qt as qt \
<o:p></o:p></p> <p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">class Node( qt.QGraphicsRectItem ) : <o:p>
</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> def __init__( self , \
sector ) : <o:p> </o:p></span></p>
<p class="MsoNormal"><span \
lang="EN-US"> super( Node , self \
).__init__( sector )<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"> <o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"> def itemChange( self , change , v ) : \
<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"> res = super( Node , self \
).itemChange( change , v )<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"> print "itemChange return \
value : ",res<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"> return \
res<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><o:p> </o:p></span></p> <p class="MsoNormal"><span lang="EN-US">b = \
qt.QGraphicsLineItem()<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">c = qt.QGraphicsLineItem()<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">a = Node(b)<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">print a.parentItem(),b<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">a.setParentItem(c)<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">print a.parentItem(), c<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">I get this output :<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US"><PyQt5.QtWidgets.QGraphicsLineItem object at \
0x8f9f194> <PyQt5.QtWidgets.QGraphicsLineItem object at \
0x8f9f194><o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">itemChange return value : <PyQt5.QtWidgets.QGraphicsLineItem \
object at 0x8f9f1dc><o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">itemChange return value : <PyQt5.QtWidgets.QGraphicsLineItem \
object at 0x8f9f1dc><o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">None <PyQt5.QtWidgets.QGraphicsLineItem object at \
0x8f9f1dc><o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><o:p> </o:p></span></p> <p class="MsoNormal"><span lang="EN-US">If \
I remove itemChange, I get this output :<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US"><PyQt5.QtWidgets.QGraphicsLineItem object at \
0xf2e6814c> <PyQt5.QtWidgets.QGraphicsLineItem object at \
0xf2e6814c><o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e68194> \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e68194><o:p></o:p></span></p> \
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">I’m using PyQt-5.0, Sip 4.14.7 and Qt \
5.1.0<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US">I tried with \
PyQt-5.0.1, sip 4.15.1 and Qt 5.1.0 without change.<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">I digged into this, basically when setParentItem \
is called itemChange is called on this item and use the return value of itemChange to \
set the parent.<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US">In C \
itemChange returns a QVariant, which must be casted as a QGraphicsItem to be set as a \
parent.<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US">This took me to \
the Chimera::parse_py_type function. Apparently, someone (QT?) registers \
QGraphicsItem as a QMetaType, but not QGraphicsLineItem.<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">If I replace :<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">_metatype = \
QMetaType::type(_name.constData());<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">By :<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">if(strcmp(_name.constData(),"QGraphicsLineItem*")==0)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> _metatype = \
QMetaType::type("QGraphicsItem*");<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US">else <o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US"> _metatype = \
QMetaType::type(_name.constData());<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><o:p> </o:p></span></p> <p class="MsoNormal"><span lang="EN-US">(I \
know how bad this is, but it’s for demonstration \
purpose.)<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><o:p> </o:p></span></p> <p class="MsoNormal"><span lang="EN-US">The \
output of the test program is then :<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba194> \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba194><o:p></o:p></span></p> \
<p class="MsoNormal"><span lang="EN-US">itemChange return value : \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba1dc><o:p></o:p></span></p> \
<p class="MsoNormal"><span lang="EN-US">itemChange return value : \
<PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba1dc><o:p></o:p></span></p> \
<p class="MsoNormal"><span lang="EN-US"><PyQt5.QtWidgets.QGraphicsLineItem object \
at 0x89ba1dc> <PyQt5.QtWidgets.QGraphicsLineItem object at \
0x89ba1dc><o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><o:p> </o:p></span></p> <p class="MsoNormal"><span lang="EN-US">Any \
ideas on how to fix this properly ?<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><o:p> </o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">Regards,<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">Yann.<o:p></o:p></span></p> </div>
</body>
</html>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
--===============1920336421172133343==--
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic