PyQt5 ListWidget add list items












2















while learning PyQt5 i found a little problem( maybe a bug) in the ListWidget Widget (and all other widgets)



the ListWidget have a addItem method overloaded :
( the code is in c++ but this is the same interface in pyqt )



void    addItem(const QString &label)
void addItem(QListWidgetItem *item)
void addItems(const QStringList &labels)


so the problem is that in PyQt5 there is no more QStringList type, and i should use a simple list of strings instead of the QStringList



but when i receive and error telling me that no method match the given paramaters :



Traceback (most recent call last):
File "main.py", line 21, in <module>
listWidget.addItem(ls)
TypeError: arguments did not match any overloaded call:
addItem(self, QListWidgetItem): argument 1 has unexpected type 'list'
addItem(self, str): argument 1 has unexpected type 'list'


Here is my code :



from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtWidgets import *

import sys


if __name__ == '__main__':

app = QApplication(sys.argv)


listWidget = QListWidget()
listWidget.show()

ls = ['test', 'test2', 'test3']

listWidget.addItem('test')
listWidget.addItem('test2')
listWidget.addItem('test3')

listWidget.addItem(ls)

sys.exit(app.exec_())









share|improve this question





























    2















    while learning PyQt5 i found a little problem( maybe a bug) in the ListWidget Widget (and all other widgets)



    the ListWidget have a addItem method overloaded :
    ( the code is in c++ but this is the same interface in pyqt )



    void    addItem(const QString &label)
    void addItem(QListWidgetItem *item)
    void addItems(const QStringList &labels)


    so the problem is that in PyQt5 there is no more QStringList type, and i should use a simple list of strings instead of the QStringList



    but when i receive and error telling me that no method match the given paramaters :



    Traceback (most recent call last):
    File "main.py", line 21, in <module>
    listWidget.addItem(ls)
    TypeError: arguments did not match any overloaded call:
    addItem(self, QListWidgetItem): argument 1 has unexpected type 'list'
    addItem(self, str): argument 1 has unexpected type 'list'


    Here is my code :



    from PyQt5 import QtGui, QtCore, QtWidgets
    from PyQt5.QtWidgets import *

    import sys


    if __name__ == '__main__':

    app = QApplication(sys.argv)


    listWidget = QListWidget()
    listWidget.show()

    ls = ['test', 'test2', 'test3']

    listWidget.addItem('test')
    listWidget.addItem('test2')
    listWidget.addItem('test3')

    listWidget.addItem(ls)

    sys.exit(app.exec_())









    share|improve this question



























      2












      2








      2








      while learning PyQt5 i found a little problem( maybe a bug) in the ListWidget Widget (and all other widgets)



      the ListWidget have a addItem method overloaded :
      ( the code is in c++ but this is the same interface in pyqt )



      void    addItem(const QString &label)
      void addItem(QListWidgetItem *item)
      void addItems(const QStringList &labels)


      so the problem is that in PyQt5 there is no more QStringList type, and i should use a simple list of strings instead of the QStringList



      but when i receive and error telling me that no method match the given paramaters :



      Traceback (most recent call last):
      File "main.py", line 21, in <module>
      listWidget.addItem(ls)
      TypeError: arguments did not match any overloaded call:
      addItem(self, QListWidgetItem): argument 1 has unexpected type 'list'
      addItem(self, str): argument 1 has unexpected type 'list'


      Here is my code :



      from PyQt5 import QtGui, QtCore, QtWidgets
      from PyQt5.QtWidgets import *

      import sys


      if __name__ == '__main__':

      app = QApplication(sys.argv)


      listWidget = QListWidget()
      listWidget.show()

      ls = ['test', 'test2', 'test3']

      listWidget.addItem('test')
      listWidget.addItem('test2')
      listWidget.addItem('test3')

      listWidget.addItem(ls)

      sys.exit(app.exec_())









      share|improve this question
















      while learning PyQt5 i found a little problem( maybe a bug) in the ListWidget Widget (and all other widgets)



      the ListWidget have a addItem method overloaded :
      ( the code is in c++ but this is the same interface in pyqt )



      void    addItem(const QString &label)
      void addItem(QListWidgetItem *item)
      void addItems(const QStringList &labels)


      so the problem is that in PyQt5 there is no more QStringList type, and i should use a simple list of strings instead of the QStringList



      but when i receive and error telling me that no method match the given paramaters :



      Traceback (most recent call last):
      File "main.py", line 21, in <module>
      listWidget.addItem(ls)
      TypeError: arguments did not match any overloaded call:
      addItem(self, QListWidgetItem): argument 1 has unexpected type 'list'
      addItem(self, str): argument 1 has unexpected type 'list'


      Here is my code :



      from PyQt5 import QtGui, QtCore, QtWidgets
      from PyQt5.QtWidgets import *

      import sys


      if __name__ == '__main__':

      app = QApplication(sys.argv)


      listWidget = QListWidget()
      listWidget.show()

      ls = ['test', 'test2', 'test3']

      listWidget.addItem('test')
      listWidget.addItem('test2')
      listWidget.addItem('test3')

      listWidget.addItem(ls)

      sys.exit(app.exec_())






      python pyqt pyqt5 qlistwidget






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 26 '18 at 3:15









      eyllanesc

      84.5k103562




      84.5k103562










      asked Mar 8 '17 at 21:49









      karimkarim

      1,40352138




      1,40352138
























          1 Answer
          1






          active

          oldest

          votes


















          3














          If you want to add a list you must use the function addItems().
          Change:



          listWidget.addItem(ls)


          to



          listWidget.addItems(ls)





          share|improve this answer
























          • Oh man, i missed the s char :s thanks

            – karim
            Mar 8 '17 at 22:08











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42682544%2fpyqt5-listwidget-add-list-items%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          If you want to add a list you must use the function addItems().
          Change:



          listWidget.addItem(ls)


          to



          listWidget.addItems(ls)





          share|improve this answer
























          • Oh man, i missed the s char :s thanks

            – karim
            Mar 8 '17 at 22:08
















          3














          If you want to add a list you must use the function addItems().
          Change:



          listWidget.addItem(ls)


          to



          listWidget.addItems(ls)





          share|improve this answer
























          • Oh man, i missed the s char :s thanks

            – karim
            Mar 8 '17 at 22:08














          3












          3








          3







          If you want to add a list you must use the function addItems().
          Change:



          listWidget.addItem(ls)


          to



          listWidget.addItems(ls)





          share|improve this answer













          If you want to add a list you must use the function addItems().
          Change:



          listWidget.addItem(ls)


          to



          listWidget.addItems(ls)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 '17 at 22:01









          eyllanesceyllanesc

          84.5k103562




          84.5k103562













          • Oh man, i missed the s char :s thanks

            – karim
            Mar 8 '17 at 22:08



















          • Oh man, i missed the s char :s thanks

            – karim
            Mar 8 '17 at 22:08

















          Oh man, i missed the s char :s thanks

          – karim
          Mar 8 '17 at 22:08





          Oh man, i missed the s char :s thanks

          – karim
          Mar 8 '17 at 22:08




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42682544%2fpyqt5-listwidget-add-list-items%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen