<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 28, 2015 at 5:17 PM, Erik Hvatum <span dir="ltr"><<a href="mailto:ice.rikh@gmail.com" target="_blank">ice.rikh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I tried your code in this form:<br><br>

<div style="color:rgb(0,0,0);background-color:rgb(245,245,245);font-style:normal;font-weight:normal;text-decoration:none">
<pre><span style="color:rgb(128,0,128)">from</span><span> </span><span>PyQt5</span><span> </span><span style="color:rgb(128,0,128)">import</span><span> </span><span>Qt</span>

<span style="color:rgb(128,0,128)">class</span><span> </span><span style="color:rgb(0,0,176)">PartFrame2dItem</span><span>(</span><span>Qt</span><span>.</span><span>QGraphicsObject</span><span>,</span><span> </span><span>Qt</span><span>.</span><span>QGraphicsRectItem</span><span>):</span>
<span>    </span><span style="color:rgb(128,0,128)">def</span><span> </span><span style="color:rgb(0,0,255)">__init__</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>):</span>
<span>        </span><span>Qt</span><span>.</span><span>QGraphicsObject</span><span>.</span><span style="color:rgb(0,0,255)">__init__</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>)</span>
<span>        </span><span>Qt</span><span>.</span><span>QGraphicsRectItem</span><span>.</span><span style="color:rgb(0,0,255)">__init__</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>)</span><span class="">
<span>        </span><span style="color:rgb(0,128,0)"># A child rectangle item</span>
<span>        </span><span style="color:rgb(0,128,0)">#self._rect_item = QGraphicsRectItem(self)</span>
<span>        </span><span style="color:rgb(0,128,0)">#self._rect_item.setZValue(-1)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span style="color:rgb(0,0,176)">setZValue</span><span>(</span><span>-</span><span style="color:rgb(0,78,130)">1</span><span>)</span>
<span>        </span><span style="color:rgb(0,128,0)">#self._rect_item.setBrush(QBrush(QColor(235,235,235)))</span>
</span><span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span style="color:rgb(0,0,176)">setBrush</span><span>(</span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QBrush</span><span>(</span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QColor</span><span>(</span><span style="color:rgb(0,78,130)">235</span><span>,</span><span style="color:rgb(0,78,130)">235</span><span>,</span><span style="color:rgb(0,78,130)">235</span><span>)))</span>

<span style="color:rgb(128,0,128)">if</span><span> </span><span style="color:rgb(0,0,255)">__name__</span><span> </span><span>==</span><span> </span><span style="color:rgb(0,128,128)">'__main__'</span><span>:</span>
<span>    </span><span style="color:rgb(128,0,128)">import</span><span> </span><span style="color:rgb(0,0,255)">sys</span>
<span>    </span><span>app</span><span> </span><span>=</span><span> </span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QApplication</span><span>(</span><span style="color:rgb(0,0,255)">sys</span><span>.</span><span style="color:rgb(0,0,255)">argv</span><span>)</span>
<span>    </span><span>gs</span><span> </span><span>=</span><span> </span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QGraphicsScene</span><span>()</span>
<span>    </span><span>gv</span><span> </span><span>=</span><span> </span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QGraphicsView</span><span>(</span><span>gs</span><span>)</span>
<span>    </span><span>gv</span><span>.</span><span style="color:rgb(0,0,176)">show</span><span>()</span>
<span>    </span><span>part_frame_2d_item</span><span> </span><span>=</span><span> </span><span style="color:rgb(0,0,176)">PartFrame2dItem</span><span>()</span>
<span>    </span><span>gs</span><span>.</span><span style="color:rgb(0,0,176)">addItem</span><span>(</span><span>part_frame_2d_item</span><span>)</span>
<span>    </span><span>app</span><span>.</span><span style="color:rgb(128,0,128)">exec</span><span>()</span></pre></div>


<br>Result:<br>> DISPLAY=:0 dpython listdev.py<br>Traceback (most recent call last):<br>  File "listdev.py", line 20, in <module><br>    part_frame_2d_item = PartFrame2dItem()<br>  File "listdev.py", line 12, in __init__<br>    self.setBrush(Qt.QBrush(Qt.QColor(235,235,235)))<br>TypeError: could not convert 'PartFrame2dItem' to 'QAbstractGraphicsShapeItem'<br><br></div><div>I wonder why you didn't see an error.  I see the same exception with various PyQt5 versions on Linux, Windows, and OS X.  Are you using PyQt4?  If so, that might account for it.<br></div></div></blockquote><div><br></div><div>I am not sure why the main program causes my interpreter to crash but I can make a test case similar to yours and now I see the same problem. Interesting, this TypeError makes me think that I didn't initialize the object properly. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br>Anyway, you might consider inheriting Qt.QObject rather than Qt.QGraphicsObject if you like the multiple inheritance approach.  </div></div></blockquote><div><br><br></div><div>Good idea! I tried that and I still get a similar TypeError, only now it is earlier in the self.setZValue() call, and the message says "could not convert PartFrame2dItem to QGraphicsItem."<br></div><div>So at least now I can see what the exception is - that is helpful. But I don't understand why I am getting this TypeError.<br><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Alternatively, the underlying C++ code may be useful as a reference if you decide to implement your own QGraphicsItemRect that inherits from only Qt.QGraphicsObject:  <a href="https://github.com/qtproject/qt/blob/4.8/src/gui/graphicsview/qgraphicsitem.cpp" target="_blank">https://github.com/qtproject/qt/blob/4.8/src/gui/graphicsview/qgraphicsitem.cpp</a> starting at line 8461, with selection highlight code starting line 7592.  There's not much to it :)<br></div></div></blockquote><div><br></div><div>Thanks! Yes, I was thinking of delving into the source and seeing what i can cannabilize from here. But if I can get multiple inheritance from QObject and QGraphicsRectItem working, that would make my life a lot easier.<br><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div><br></div><div>Cheers,<br></div><div>Erik<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, Feb 27, 2015 at 10:30 AM, Alan Ezust <span dir="ltr"><<a href="mailto:alan.ezust@gmail.com" target="_blank">alan.ezust@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div><div><div>I had a QGraphicsRectItem before that I needed to add signals to.<br></div><br></div>I had trouble getting multiple inheritance to work between QGraphicsObject and QGraphicsRectItem. As soon as I tried to call self.setBrush(), the interpreter crashed, and I am not able to see any kind of error message that indicates what might be the problem.<br><br><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:12pt"><br><span style="color:rgb(0,0,128);font-weight:bold">class </span>PartFrame2dItem(QGraphicsObject<span style="color:rgb(204,120,50)">, </span>QGraphicsRectItem):<br>def __init__(self):<br></pre><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:12pt;margin-left:40px">QGraphicsObject.<span style="color:rgb(178,0,178)">__init__</span>(<span style="color:rgb(148,85,141)">self</span>)<br>QGraphicsRectItem.<span style="color:rgb(178,0,178)">__init__</span>(<span style="color:rgb(148,85,141)">self</span>)<br><span style="color:rgb(128,128,128);font-style:italic"># A child rectangle item<br></span><span style="color:rgb(128,128,128);font-style:italic">#self._rect_item = QGraphicsRectItem(self)<br></span><span style="color:rgb(128,128,128);font-style:italic">#self._rect_item.setZValue(-1)<br></span><span style="color:rgb(148,85,141)">self</span>.setZValue(-<span style="color:rgb(0,0,255)">1</span>)<br><span style="color:rgb(128,128,128);font-style:italic">#self._rect_item.setBrush(QBrush(QColor(235,235,235)))<br></span><span style="color:rgb(148,85,141)">self</span>.setBrush(QBrush(QColor(<span style="color:rgb(0,0,255)">235</span><span style="color:rgb(204,120,50)">,</span><span style="color:rgb(0,0,255)">235</span><span style="color:rgb(204,120,50)">,</span><span style="color:rgb(0,0,255)">235</span>)))</pre>Is there something wrong with my __init__?<br></div><div>Why would it crash like that on the setBrush() ?<br></div><div><br>So I redesigned it so that the QGraphicsObject creates a child QGraphicsRectItem. But now, when I select the item from the view, I don't see any dotted line selection indicator around the thing. <br><br></div>Am I supposed to override and delegate some event handler or method to the from the QGraphicsObject to the QGraphicsRectItem in order to see that dotted line selection effect?<br><br></div>Thanks for any insights you might have. <br><br><br></div>
<br></div></div>_______________________________________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br></div></div>
<br>_______________________________________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br></div></div>