<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Le 04/09/2015 00:14, michael h a
      écrit :<br>
    </div>
    <blockquote
cite="mid:CAD0nt=Fr-GztLMcpqswdDRajKwqUN0hN3CsZqkwxOSyboANyTg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
              <div dir="ltr">
                <div><br>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div>class RectItem(QGraphicsRectItem):</div>
                  <div>    selectedChange = pyqtSignal(str)</div>
                  <div><br>
                  </div>
                </div>
                <div>And I got error:</div>
                <div>
                  <div>test3.py, line 48, in <module></div>
                  <div>    rect.selectedChange.connect(message)</div>
                  <div>TypeError: RectItem cannot be converted to
                    PyQt5.QtCore.QObject in this context</div>
                </div>
                <div><br>
                </div>
                How to solve this?<span class=""><font color="#888888">
                    <div><br clear="all">
                      <div>
                        <div>Zdenko</div>
                      </div>
                      <input name="virtru-metadata"
value="{"email-policy":{"state":"closed","expirationUnit":"days","disableCopyPaste":false,"disablePrint":false,"disableForwarding":false,"expires":false},"attachments":{}}"
                        type="hidden"></div>
                  </font></span></div>
              <br>
            </blockquote>
            <div><br>
            </div>
            <div>Zdenko,</div>
            <div><br>
            </div>
            <div><span style="font-size:12.8px">QGraphicsRectItem does
                not inherit from QObject, while</span> <span
                style="font-size:12.8px">QGraphicsTextItem does.</span></div>
            <div><span style="font-size:12.8px"><br>
              </span></div>
            <div><span style="font-size:12.8px">See: <a
                  moz-do-not-send="true"
href="http://stackoverflow.com/questions/4922801/adding-signals-slots-qobject-to-qgraphicsitem-performance-hit"><a class="moz-txt-link-freetext" href="http://stackoverflow.com/questions/4922801/adding-signals-slots-qobject-to-qgraphicsitem-performance-hit">http://stackoverflow.com/questions/4922801/adding-signals-slots-qobject-to-qgraphicsitem-performance-hit</a></a></span><br>
            </div>
            <div><span style="font-size:12.8px"><br>
              </span></div>
            <div><span style="font-size:12.8px">The first answer alludes
                to either inheriting directly from </span><span
                style="font-size:12.8px">QGraphicsObject, or using
                multiple inheritance e.g. SomeItem(</span><span
                style="font-size:12.8px">QGraphicsRectItem, QObject) but
                i'm not sure this works from python.</span></div>
            <div><span style="font-size:12.8px"><br>
              </span></div>
            <div><span style="font-size:12.8px">The second answer listed
                hints at a signal emitting QObject that can emit signals
                on behalf of the RectItems.</span></div>
            <div><span style="font-size:12.8px"><br>
              </span></div>
            <div><span style="font-size:12.8px">- mh</span></div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
PyQt mailing list    <a class="moz-txt-link-abbreviated" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a class="moz-txt-link-freetext" href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></pre>
    </blockquote>
    I use this method in this case:<br>
    <br>
    ---------------------------------<br>
    class RectItem(QGraphicsRectItem):<br>
        def __init__(self, parent=None):<br>
            super(RectItem, self).__init__(-30, -30, 30, 30, parent)<br>
            pen = QPen(Qt.red, 2, Qt.SolidLine,<br>
                       Qt.RoundCap, Qt.RoundJoin)<br>
            self.setPen(pen)<br>
            self._selectedChange = SelectedChange()<br>
    <br>
        def selectedChange():<br>
            def fget(self):<br>
                return self._selectedChange.selectedChange<br>
            return locals()<br>
        selectedChange = property(**selectedChange())<br>
    <br>
        def mousePressEvent(self, event):<br>
            self.selectedChange.emit('RectItem')<br>
            super(RectItem, self).mousePressEvent(event)<br>
    <br>
    class SelectedChange(QObject):<br>
        selectedChange = pyqtSignal(str)<br>
        def __init__(self):<br>
            super(SelectedChange, self).__init__()<br>
    -------------------------------------<br>
    <br>
    Others QGraphicsItems can share the same signal, if the the
    signature is the same of course.<br>
  </body>
</html>