I don't understand how
index
is passed intoshowPath()
You connect the widget's click signal to showPath
explicitly:
self.treeView.clicked.connect(self.showPath)
part of this signal is the index
of the specific item clicked on; this is passed as an argument to showPath
automatically.
Also why
self.filename
andself.filepath
are not passed to the instance?
They are instance attributes, they belong to the instance and are accessible to all methods of that instance. They are created in givePathName()
, and are then part of the TreeViewWidget
instance object. They start with self.
because that is, by convention, the name given to the instance in instance methods (and the implicit first argument to those methods).
Putting that together:
def showPath(self, index):
# ^ the instance object, so you can access its attributes
# ^ the index of the specific item clicked