member Basu wrote:
> I'm writing an application with PyQt as the GUI toolkit. I have a
> function that returns a simple list and I would like to update a List
> View widget with it. However I can't get it to work. I'm not sure if I
> need to subclass one of the Model classes, because it is just a list.
> Can someone point me to a simple tutorial or give me instructions on how
> to go about doing this?
The attached example should help. Also see the examples included with PyQt.
-- Gerhard
from PyQt4 import QtCore, QtGui
import sys
class MyDialog(QtGui.QDialog):
def __init__(self, parent):
super(QtGui.QDialog, self).__init__(parent)
self.layout = QtGui.QVBoxLayout(self)
self.resize(400, 300)
self.listWidget = QtGui.QListWidget(self)
self.layout.addWidget(self.listWidget)
buttonBox = QtGui.QDialogButtonBox(self)
buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
self.layout.addWidget(buttonBox)
QtCore.QObject.connect(buttonBox, QtCore.SIGNAL("accepted()"), self.accept)
def set_list(self, lst):
for item in lst:
listItem = QtGui.QListWidgetItem(str(item), self.listWidget)
def accept(self):
selected_items = ", ".join([str(item.text()) for item in self.listWidget.selectedItems()])
print "selected:", selected_items
self.close()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
dlg = MyDialog(None)
lst = [3,4,5]
dlg.set_list(lst)
dlg.exec_()
--
http://mail.python.org/mailman/listinfo/python-list