<div><b>Is there any better, more efficient way to achieve the following:</b></div><div><br></div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font color="#009900">from PyQt4.QtCore import *<br>from PyQt4.QtGui import *<br>import ui_list<br>class Test(QDialog,ui_list.Ui_Dialog):<br><span class="Apple-tab-span" style="white-space:pre"> </span>def __init__(self, parent=None):<br>
<span class="Apple-tab-span" style="white-space:pre"> </span>super(Test, self).__init__(parent)<br><span class="Apple-tab-span" style="white-space:pre"> </span>self.setupUi(self)<br><span class="Apple-tab-span" style="white-space:pre"> </span>for i in range(10):<br>
<span class="Apple-tab-span" style="white-space:pre"> </span>item = QListWidgetItem("Item %i" % i)<br><span class="Apple-tab-span" style="white-space:pre"> </span>self.listWidget.addItem(item)<br> <span class="Apple-tab-span" style="white-space:pre"> </span>#self.listWidget.itemClicked.connect(self.printItemText)<br>
<span class="Apple-tab-span" style="white-space:pre"> </span>self.connect(self.listWidget, SIGNAL("itemSelectionChanged()"), self.printItemText)<br> <span class="Apple-tab-span" style="white-space:pre"> <br></span><span class="Apple-tab-span" style="white-space:pre"> </span>def printItemText(self):<br>
<span class="Apple-tab-span" style="white-space:pre"> </span>items = self.listWidget.selectedItems()<br><span class="Apple-tab-span" style="white-space:pre"> </span>x=[]<br><span class="Apple-tab-span" style="white-space:pre"> </span>for i in range(len(items)):<br>
<span class="Apple-tab-span" style="white-space:pre"> </span>x.append(str(self.listWidget.selectedItems()[i].text()))<br><span class="Apple-tab-span" style="white-space:pre"> </span>print x<span class="Apple-tab-span" style="white-space:pre"> </span> <br>
if __name__ == "__main__":<br><span class="Apple-tab-span" style="white-space:pre"> </span>import sys<br><span class="Apple-tab-span" style="white-space:pre"> </span>app = QApplication(sys.argv)<br><span class="Apple-tab-span" style="white-space:pre"> </span>form = Test()<br>
<span class="Apple-tab-span" style="white-space:pre"> </span>form.show()<br><span class="Apple-tab-span" style="white-space:pre"> </span>app.exec_()</font></blockquote><div><br></div><div><b>I couldnt find any way to get a list with all the selected items as text, so I had to create this loop.</b></div>
<div><b><br></b></div><div><b>Here is the code from the ui_list.py from qtdesigner:</b></div><div><br></div><div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font color="#009900">from PyQt4 import QtCore, QtGui<br>try:<br> _fromUtf8 = QtCore.QString.fromUtf8<br>except AttributeError:<br> _fromUtf8 = lambda s: s<br>class Ui_Dialog(object):<br> def setupUi(self, Dialog):<br>
Dialog.setObjectName(_fromUtf8("Dialog"))<br> Dialog.resize(231, 315)<br> Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))<br>
self.listWidget = QtGui.QListWidget(Dialog)<br> self.listWidget.setGeometry(QtCore.QRect(10, 10, 211, 291))<br> self.listWidget.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)<br> self.listWidget.setObjectName(_fromUtf8("listWidget"))<br>
self.retranslateUi(Dialog)<br> QtCore.QMetaObject.connectSlotsByName(Dialog)<br> def retranslateUi(self, Dialog):<br> pass</font></blockquote></div><div><br></div><div><b>thanks in advance</b></div>
-- <br>Christos Parliaros<br>VFX Technical Director and Artist<br><a href="http://www.cparliaros.com" target="_blank">www.cparliaros.com</a><br>