Reputation: 1859
I'm trying to make list2 to clear whatever it holds in it and assign to it a new value, but I'm getting an error when trying to use my own method fillListView
instead of built in functions like self.list2.clear
. How can I avoid it and make it work as expected?
class Ui(object):
def setupUi(self, Ui):
self.List1= QtGui.QListWidget(self.ProjectNavigator)
self.List1.setGeometry(QtCore.QRect(10, 50, 141, 241))
self.List1.setObjectName(_fromUtf8("List1"))
self.List2 = QtGui.QListWidget(self.ProjectNavigator)
self.List2.setGeometry(QtCore.QRect(170, 50, 141, 241))
self.List2.setObjectName(_fromUtf8("List2"))
### QtCore.QObject.connect(self.ProjectType, QtCore.SIGNAL(_fromUtf8("itemSelectionChanged()")), self.List2.clear) This one works but it's only clear the list
QtCore.QObject.connect(self.ProjectType, QtCore.SIGNAL(_fromUtf8("itemSelectionChanged()")), self.fillListView())
and here is my method:
def fillListView(self):
self.List2.clear,
self.List2.addItem("TEST1")
self.List2.addItem("TEST2")
traceback:
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 2 has unexpected type 'str'
Upvotes: 0
Views: 370
Reputation: 7036
Your problem is that when you connect your signal with:
QtCore.QObject.connect(self.ProjectType, QtCore.SIGNAL(_fromUtf8("itemSelectionChanged()")), self.fillListView())
You are passing the return value of self.fillListView()
, which is None
, instead of the function itself.
Try:
QtCore.QObject.connect(self.ProjectType, QtCore.SIGNAL(_fromUtf8("itemSelectionChanged()")), self.fillListView)
Also, in your fillListView()
method, you might want to actually run the clear method with:
self.list2.clear() # note the parethesis
Also, as the other commentor said, you should decide if you want to call it self.list2
or self.List2
. I would suggest lower case.
Upvotes: 1