<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Le 14/02/19 à 14:56, J Barchan a
      écrit :<br>
    </div>
    <blockquote type="cite"
cite="mid:CABz3M__AepwdFsxX-BkkxqMcn=owGX9h=uDHKHy+9Rg6jq=qwQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div dir="ltr">
          <div class="gmail_default"
            style="font-family:tahoma,sans-serif"><br>
          </div>
        </div>
        <br>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Thu, 14 Feb 2019 at
            13:34, J Barchan <<a href="mailto:jnbarchan@gmail.com"
              moz-do-not-send="true">jnbarchan@gmail.com</a>> wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
            0.8ex;border-left:1px solid
            rgb(204,204,204);padding-left:1ex">
            <div dir="ltr">
              <div dir="ltr">
                <div dir="ltr">
                  <div dir="ltr">
                    <div style="font-family:tahoma,sans-serif">This may
                      be as much a Python question as a PyQt one.  I
                      come from a C++ background.  I do not understand
                      the syntax/code I need in a class I am deriving
                      from a PyQt class to allow a new parameter to be
                      passed to the constructor.</div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div style="font-family:tahoma,sans-serif">I see
                      that I asked this question a long time ago at <a
href="https://stackoverflow.com/questions/45999732/python3-typing-overload-and-parameters"
                        target="_blank" moz-do-not-send="true">https://stackoverflow.com/questions/45999732/python3-typing-overload-and-parameters</a>
                      but never got an answer.</div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div style="font-family:tahoma,sans-serif">I now
                      want to sub-class from <span
                        style="font-family:monospace,monospace">QListWidgetItem</span>. 
                      That starts with these constructors:</div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div><span style="font-family:monospace,monospace">QListWidgetItem(QListWidget
                        *parent = nullptr, int type = Type)<br>
                        QListWidgetItem(const QString &text,
                        QListWidget *parent = nullptr, int type = Type)<br>
                        QListWidgetItem(const QIcon &icon, const
                        QString &text, QListWidget *parent =
                        nullptr, int type = Type)<br>
                        QListWidgetItem(const QListWidgetItem
                        &other)</span></div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div style="font-family:tahoma,sans-serif">My
                      sub-class should still support these
                      constructors.  In addition to the existing <span
                        style="font-family:monospace,monospace">text</span>,
                      I want my sub-class to be able to store a new
                      optional <span
                        style="font-family:monospace,monospace">value</span>.
                      At minimum/sufficient I want a new possible
                      constructor like one of the following:</div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div style="font-family:tahoma,sans-serif"><span
                        style="font-family:monospace,monospace">MyListWidgetItem(<span
                          style="font-family:monospace,monospace">const
                          QString &text, <span
                            style="font-family:monospace,monospace"><span
                              style="color:rgb(255,0,255)">const
                              QVariant &value,</span> </span></span>QListWidget
                        *parent = nullptr, int type = Type)</span></div>
                    <div style="font-family:tahoma,sans-serif"><span
                        style="font-family:monospace,monospace"># or<br>
                      </span></div>
                    <div style="font-family:tahoma,sans-serif">
                      <div style="font-family:tahoma,sans-serif"><span
                          style="font-family:monospace,monospace">MyListWidgetItem(<span
                            style="font-family:monospace,monospace">const
                            QString &text, <span
                              style="font-family:monospace,monospace"><span
                                style="color:rgb(255,0,255)">QVariant
                                value = QVariant(),</span> </span></span>QListWidget
                          *parent = nullptr, int type = Type)</span></div>
                      <div style="font-family:tahoma,sans-serif"><br>
                      </div>
                    </div>
                    <div style="font-family:tahoma,sans-serif">So for
                      Python I know I start with a <i>typing overload</i>
                      definition (for my editor) like <br>
                    </div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div><span style="font-family:monospace,monospace">@typing.overload</span></div>
                    <div><span style="font-family:monospace,monospace">def
                        MyListWidgetItem(self, text: str, value:
                        typing.Any, parent: QListWidget=None, type:
                        int=Type)</span></div>
                    <div><span style="font-family:monospace,monospace">   
                        pass<br>
                      </span></div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div style="font-family:tahoma,sans-serif">Then I
                      get to the <i>definition</i> bit.  To cater for
                      everything am I supposed to do:</div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div style="font-family:tahoma,sans-serif">
                      <div><span style="font-family:monospace,monospace"><span
                            class="gmail_default"
                            style="font-family:tahoma,sans-serif"></span>def
                          __init__(self, *__args)</span></div>
                      <div><span style="font-family:monospace,monospace">   
                          # Now what??<br>
                        </span></div>
                      <div><span style="font-family:monospace,monospace">   
                          super().__init__(__args)<br>
                        </span></div>
                    </div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div style="font-family:tahoma,sans-serif">Is that
                      how we do it?  Is it then my responsibility to
                      look at <span
                        style="font-family:monospace,monospace">__args[1]</span>
                      to see if it's my <span
                        style="font-family:monospace,monospace">value</span>
                      argument?  And remove it from <span
                        style="font-family:monospace,monospace">__args</span>
                      before passing it onto <span
                        style="font-family:monospace,monospace">super().__init__(__args)</span>?<br>
                    </div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div style="font-family:tahoma,sans-serif">Or, am I
                      not supposed to deal with <span
                        style="font-family:monospace,monospace">__args</span>,
                      and instead have some definition with all possible
                      parameters explicitly and deal with them like
                      that?</div>
                    <div style="font-family:tahoma,sans-serif"><br>
                    </div>
                    <div style="font-family:tahoma,sans-serif">Or what? 
                      This is pretty fundamental to sub-classing to add
                      parameters where you don't own the code of what
                      you're deriving from.  It's easy in C-type
                      languages; I'm finding it real to hard to
                      understand what I can/can't/am supposed to do for
                      this, I'd be really gratefully for a couple of
                      lines to show me, please...! :)<br clear="all">
                    </div>
                    <br>
                    -- <br>
                    <div dir="ltr"
                      class="gmail-m_-6986055192168723530gmail_signature">
                      <div dir="ltr">
                        <div>
                          <div dir="ltr">
                            <div><span
                                style="font-family:tahoma,sans-serif">Kindest,</span></div>
                            <div><span
                                style="font-family:tahoma,sans-serif">Jonathan</span></div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br clear="all">
        <div style="font-family:tahoma,sans-serif" class="gmail_default">P.S.</div>
        <div style="font-family:tahoma,sans-serif" class="gmail_default">I
          think I got my overload a bit mixed up.  I meant I (think I)
          will have:</div>
        <div style="font-family:tahoma,sans-serif" class="gmail_default"><br>
        </div>
        <div style="font-family:tahoma,sans-serif" class="gmail_default"><span
            style="font-family:monospace,monospace">class
            MyListWidgetItem(QListWidgetItem)</span><span
            style="font-family:monospace,monospace"><span
              class="gmail_default"
              style="font-family:tahoma,sans-serif"><br>
            </span></span></div>
        <div style="font-family:tahoma,sans-serif" class="gmail_default"><span
            style="font-family:monospace,monospace"><span
              class="gmail_default"
              style="font-family:tahoma,sans-serif"></span></span>
          <div>
            <div style="font-family:tahoma,sans-serif">
              <div>
                <div><span style="font-family:monospace,monospace">   
                    @typing.overload</span></div>
                <div><span style="font-family:monospace,monospace"><span
                      style="font-family:monospace,monospace">    def
                      __init__(<span
                        style="font-family:monospace,monospace">self,
                        text: str, value: typing.Any, parent:
                        QListWidget=None, type: int=Type)</span></span></span>
                  <div><span style="font-family:monospace,monospace">       
                      pass</span></div>
                  <div><span style="font-family:monospace,monospace"><br>
                    </span></div>
                  <span style="font-family:monospace,monospace">    def
                    __init__(self, *__args)</span></div>
              </div>
              <div><span style="font-family:monospace,monospace">       
                  # Now what??<br>
                </span></div>
              <div><span style="font-family:monospace,monospace">       
                  super().__init__(__args)<br>
                </span></div>
            </div>
            <div style="font-family:tahoma,sans-serif"><br>
            </div>
            <span style="font-family:monospace,monospace"></span></div>
        </div>
        <br>
        -- <br>
        <div dir="ltr" class="gmail_signature">
          <div dir="ltr">
            <div>
              <div dir="ltr">
                <div><span style="font-family:tahoma,sans-serif">Kindest,</span></div>
                <div><span style="font-family:tahoma,sans-serif">Jonathan</span></div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-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>
    <p>Hi,<br>
      <br>
      I use just that:<br>
      <br>
      class ListItem(QListWidgetItem):<br>
          def __init__(self, img, text, parent=None):<br>
              super().__init__(parent)<br>
              icon = QIcon()<br>
              icon.addPixmap(QPixmap(img), QIcon.Normal, QIcon.Off)<br>
              self.setIcon(icon)<br>
              self.setText(text)<br>
      <br>
      The arguments are examples, not mandatory.<br>
      <br>
      Vincent<br>
    </p>
  </body>
</html>