Re: (PyQt4) QtGui QListWidget adding new item problem
Hi everyone.
At first:
- My sys.version output:
2.7.3 (default, Aug 1 2012, 05:16:07)
[GCC 4.6.3] - 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:
Code:
pyuic4 -x blabla.ui -o c.py
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:
Quote:
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:
Code:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled2.ui'
#
# Created: Fri Aug 31 04:05:57 2012
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8
= QtCore.
QString.
fromUtf8except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Form(object:(
def setupUi(self, Form:(
Form.setObjectName(_fromUtf8("Form"))
Form.resize(658, 527)
self.
pushButton.
setGeometry(QtCore.
QRect(170,
260,
89,
27)) self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.
listWidget.
setGeometry(QtCore.
QRect(150,
20,
256,
192)) self.listWidget.setObjectName(_fromUtf8("listWidget"))
self.retranslateUi(Form)
QtCore.
QObject.
connect(self.
pushButton, QtCore.
SIGNAL(_fromUtf8
("clicked()")), self.
selectFile)
def retranslateUi(self, Form:(
__sortingEnabled = self.listWidget.isSortingEnabled()
self.listWidget.setSortingEnabled(False)
self.listWidget.setSortingEnabled(__sortingEnabled)
def selectFile(self:(
for x in range(0,5:(
self.listWidget.addItem(item)
self.listWidget.item = self.listWidget.item(x)
print("Worked for x="+str(x))
if __name__ == "__main__":
import sys
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
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.