Results 1 to 2 of 2

Thread: PyQT Listview index to string

  1. #1
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    1
    Qt products

    Default 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
    Qt Code:
    1. data = QtCore.QStringList()
    2. data << " "
    3.  
    4. self.listView = QtGui.QListView(self)
    5. self.listView.setGeometry(40,80,400,300)
    6. self.listView.clicked.connect(self.on_treeView_clicked)
    7. self.listView.setSelectionMode(QAbstractItemView.MultiSelection)
    8. model = QtGui.QStringListModel(data)
    9.  
    10. self.listView.setModel(model)
    To copy to clipboard, switch view to plain text mode 

    Getting list of items
    Qt Code:
    1. def getLoc(self):
    2. file = str(QFileDialog.getExistingDirectory(self, "Select Directory"))
    3. loc = file
    4. self.lbl.setText(loc)
    5. location = file
    6. fileList = os.listdir(location)
    7. data = QtCore.QStringList()
    8. data << fileList
    9. model = QtGui.QStringListModel(data)
    10. self.listView.setModel(model)
    To copy to clipboard, switch view to plain text mode 

    And my attempt at converting indexes to strings :
    Qt Code:
    1. @QtCore.pyqtSlot(QtCore.QModelIndex)
    2. def on_treeView_clicked(self, index):
    3. itms = self.listView.selectedIndexes()
    4. for data in itms:
    5. print data.row()
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    1
    Qt products

    Default Re: PyQT Listview index to string

    Sorted, I needed this:

    Qt Code:
    1. print data.data().toString()
    2.  
    3. instead of this:
    4.  
    5. print data.row()
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 3
    Last Post: 8th June 2011, 06:36
  2. Upgrading from PyQt 4.5 to PyQt 4.7
    By RogerCon in forum Installation and Deployment
    Replies: 0
    Last Post: 14th July 2010, 18:52
  3. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  4. Int to String - manipulating string
    By mickey in forum General Programming
    Replies: 6
    Last Post: 5th November 2007, 20:11
  5. Replies: 1
    Last Post: 30th June 2006, 05:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.