PyQT Listview index to string
Heya
I'm trying to get a list of items from 1 listview and add them to another listview and then use it in rest of my script.
The way I thought to do it is to get listView_A >indexes > convert to names > add names to listView_B > execute script with names in listview_B (so I have to convert it again from indexes to names)
Now I don't know how to convert indexes to name. I found few clues but nothing worked.
Creation of UI
Code:
data << " "
self.listView.setGeometry(40,80,400,300)
self.listView.clicked.connect(self.on_treeView_clicked)
self.listView.setModel(model)
Getting list of items
Code:
def getLoc(self):
file = str
(QFileDialog.
getExistingDirectory(self,
"Select Directory")) loc = file
self.lbl.setText(loc)
location = file
fileList = os.listdir(location)
data << fileList
self.listView.setModel(model)
And my attempt at converting indexes to strings :
Code:
def on_treeView_clicked(self, index):
itms = self.listView.selectedIndexes()
for data in itms:
print data.row()
Re: PyQT Listview index to string
Sorted, I needed this:
Code:
print data.data().toString()
instead of this:
print data.row()