PDA

View Full Version : PyQT Listview index to string



Dariusz
28th September 2013, 00:26
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


data = QtCore.QStringList()
data << " "

self.listView = QtGui.QListView(self)
self.listView.setGeometry(40,80,400,300)
self.listView.clicked.connect(self.on_treeView_cli cked)
self.listView.setSelectionMode(QAbstractItemView.M ultiSelection)
model = QtGui.QStringListModel(data)

self.listView.setModel(model)

Getting list of items


def getLoc(self):
file = str(QFileDialog.getExistingDirectory(self, "Select Directory"))
loc = file
self.lbl.setText(loc)
location = file
fileList = os.listdir(location)
data = QtCore.QStringList()
data << fileList
model = QtGui.QStringListModel(data)
self.listView.setModel(model)

And my attempt at converting indexes to strings :


@QtCore.pyqtSlot(QtCore.QModelIndex)
def on_treeView_clicked(self, index):
itms = self.listView.selectedIndexes()
for data in itms:
print data.row()

Dariusz
28th September 2013, 09:05
Sorted, I needed this:


print data.data().toString()

instead of this:

print data.row()