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 << " "
self.listView.setGeometry(40,80,400,300)
self.listView.clicked.connect(self.on_treeView_clicked)
self.listView.setModel(model)
data = QtCore.QStringList()
data << " "
self.listView = QtGui.QListView(self)
self.listView.setGeometry(40,80,400,300)
self.listView.clicked.connect(self.on_treeView_clicked)
self.listView.setSelectionMode(QAbstractItemView.MultiSelection)
model = QtGui.QStringListModel(data)
self.listView.setModel(model)
To copy to clipboard, switch view to plain text mode
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 << fileList
self.listView.setModel(model)
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)
To copy to clipboard, switch view to plain text mode
And my attempt at converting indexes to strings :
def on_treeView_clicked(self, index):
itms = self.listView.selectedIndexes()
for data in itms:
print data.row()
@QtCore.pyqtSlot(QtCore.QModelIndex)
def on_treeView_clicked(self, index):
itms = self.listView.selectedIndexes()
for data in itms:
print data.row()
To copy to clipboard, switch view to plain text mode
Bookmarks