Results 1 to 1 of 1

Thread: (PyQt4) QtGui QListWidget adding new item problem

  1. #1
    Join Date
    Sep 2012
    Location
    Ankara
    Posts
    15
    Thanks
    3
    Qt products
    Platforms
    Unix/X11

    Default Re: (PyQt4) QtGui QListWidget adding new item problem

    Hi everyone.

    At first:

    1. My sys.version output:
      2.7.3 (default, Aug 1 2012, 05:16:07)
      [GCC 4.6.3]
    2. My OS:
      bq. Ubuntu
      Release 12.04 (precise) 32-bit


    I used Qt 4 Designer for my GUI. And made a form contains a QListWidget and a QPushButton. Then used this command line for converting XML file to py file:

    Qt Code:
    1. pyuic4 -x blabla.ui -o c.py
    To copy to clipboard, switch view to plain text mode 

    I want to add numbers to list widget when button clicked. I wrote the code below. It can add a blank row and fill it with firs number. In second loop it add a blank row and print this error:

    Traceback (most recent call last):
    File "b.py", line 48, in selectFile
    self.listWidget.item = self.listWidget.item(x)
    TypeError: 'QListWidgetItem' object is not callable
    Here is my code:

    Qt Code:
    1. # -*- coding: utf-8 -*-
    2.  
    3. # Form implementation generated from reading ui file 'untitled2.ui'
    4. #
    5. # Created: Fri Aug 31 04:05:57 2012
    6. # by: PyQt4 UI code generator 4.9.1
    7. #
    8. # WARNING! All changes made in this file will be lost!
    9.  
    10. from PyQt4 import QtCore, QtGui
    11.  
    12. try:
    13. _fromUtf8 = QtCore.QString.fromUtf8
    14. except AttributeError:
    15. _fromUtf8 = lambda s: s
    16.  
    17. class Ui_Form(object:(
    18. def setupUi(self, Form:(
    19. Form.setObjectName(_fromUtf8("Form"))
    20. Form.resize(658, 527)
    21. self.pushButton = QtGui.QPushButton(Form)
    22. self.pushButton.setGeometry(QtCore.QRect(170, 260, 89, 27))
    23. self.pushButton.setObjectName(_fromUtf8("pushButton"))
    24. self.listWidget = QtGui.QListWidget(Form)
    25. self.listWidget.setGeometry(QtCore.QRect(150, 20, 256, 192))
    26. self.listWidget.setObjectName(_fromUtf8("listWidget"))
    27.  
    28.  
    29.  
    30.  
    31. self.retranslateUi(Form)
    32. QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.selectFile)
    33. QtCore.QMetaObject.connectSlotsByName(Form)
    34.  
    35. def retranslateUi(self, Form:(
    36. Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
    37. self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
    38. __sortingEnabled = self.listWidget.isSortingEnabled()
    39. self.listWidget.setSortingEnabled(False)
    40. self.listWidget.setSortingEnabled(__sortingEnabled)
    41.  
    42. def selectFile(self:(
    43. for x in range(0,5:(
    44. item=QtGui.QListWidgetItem()
    45. self.listWidget.addItem(item)
    46. self.listWidget.item = self.listWidget.item(x)
    47. self.listWidget.item.setText(QtGui.QApplication.translate("Form", str(x), None, QtGui.QApplication.UnicodeUTF8))
    48. print("Worked for x="+str(x))
    49.  
    50.  
    51.  
    52. if __name__ == "__main__":
    53. import sys
    54. app = QtGui.QApplication(sys.argv)
    55. Form = QtGui.QWidget()
    56. ui = Ui_Form()
    57. ui.setupUi(Form)
    58. Form.show()
    59. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    What’s the problem?
    Please help me.
    Sorry for bad English.


    Added after 1:


    I'm so sorry about it. I searched a long for this problem. Now I see I had syntax error.
    So sorry about it.
    Last edited by mshemuni; 4th September 2012 at 04:05.

Similar Threads

  1. QListWidget, help adding new items.
    By JeremyRussell in forum Newbie
    Replies: 4
    Last Post: 6th April 2011, 23:54
  2. Replies: 1
    Last Post: 22nd February 2010, 10:53
  3. [QtGui] Problem with a QTextBrowser
    By Auliyaa in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2010, 07:51
  4. problem with "QListWidget" item
    By impeteperry in forum Qt Programming
    Replies: 6
    Last Post: 16th April 2007, 18:00
  5. [Qt4]: Adding centered items in QListWidget
    By Jojo in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2006, 20:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.