def loadMovieCollection(self): json = urllib2.urlopen("http://" + HOST_IP + ":" + HOST_PORT + "/moviecollection").read() movieCollection = jsonpickle.decode(json) model = QStandardItemModel(self.ui.lvMovies) for movie in movieCollection: item = QStandardItem(movie['title']) item.setData(movie['ean']) model.appendRow(item) self.ui.lvMovies.setModel(model)
def update_filename_box(self): doing_multiple = self.doing_multiple model = QStandardItemModel() self.filename_box.setModel(model) self.icon_file_names.sort(key=sort_key) if doing_multiple: item = QStandardItem(_('Open to see checkboxes')) else: item = QStandardItem('') model.appendRow(item) for i,filename in enumerate(self.icon_file_names): item = QStandardItem(filename) if doing_multiple: item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setData(Qt.Unchecked, Qt.CheckStateRole) else: item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) icon = QIcon(os.path.join(self.icon_folder, filename)) item.setIcon(icon) model.appendRow(item)
def update_filename_box(self): doing_multiple = self.multiple_icon_cb.isChecked() model = QStandardItemModel() self.filename_box.setModel(model) self.icon_file_names.sort(key=sort_key) if doing_multiple: item = QStandardItem(_('Open to see checkboxes')) else: item = QStandardItem('') model.appendRow(item) for i, filename in enumerate(self.icon_file_names): item = QStandardItem(filename) if doing_multiple: item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setData(Qt.Unchecked, Qt.CheckStateRole) else: item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) icon = QIcon(os.path.join(config_dir, 'cc_icons', filename)) item.setIcon(icon) model.appendRow(item)
class Ui_ListServers(QtGui.QDialog): def __init__(self,parent=None): self.confirm = None self.__index = None self.__model = QStandardItemModel() QtGui.QDialog.__init__(self, parent) self.setupUi(self) def setupUi(self, Dialog): Dialog.setObjectName(_fromUtf8("LIst Servers")) Dialog.resize(400, 300) self.verticalLayout_2 = QtGui.QVBoxLayout(Dialog) self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.label = QtGui.QLabel(Dialog) font = QtGui.QFont() font.setPointSize(22) font.setBold(True) font.setWeight(75) self.label.setFont(font) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setObjectName(_fromUtf8("label")) self.verticalLayout.addWidget(self.label) self.list_servers = QtGui.QListView(Dialog) self.list_servers.setObjectName(_fromUtf8("list_servers")) self.verticalLayout.addWidget(self.list_servers) self.buttonBox = QtGui.QDialogButtonBox(Dialog) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) self.buttonBox.setObjectName(_fromUtf8("buttonBox")) self.verticalLayout.addWidget(self.buttonBox) self.verticalLayout_2.addLayout(self.verticalLayout) self.list_servers.setModel(self.__model) self.retranslateUi(Dialog) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject) QtCore.QObject.connect(self.list_servers, QtCore.SIGNAL(_fromUtf8("clicked(QModelIndex)")), self.listServersClicked) QtCore.QMetaObject.connectSlotsByName(Dialog) def listServersClicked(self, index): print "Lista Clicada" self.__index = index def getItem(self): return self.__model.itemFromIndex(self.__index) def getModel(self): return self.__model def retranslateUi(self, Dialog): Dialog.setWindowTitle(_translate("Dialog", "Dialog", None)) self.label.setText(_translate("Dialog", "SERVERS", None)) def add(self, text): item= QStandardItem(text) self.__model.appendRow(item)
## ] ## ## for food in foods: ## # create an item with a caption ## item = QStandardItem(food) ## ## # add a checkbox to it ## item.setCheckable(True) ## ## # Add the item to the model ## model.appendRow(item) for pick in cat[-40].picks: # create an item with a caption item = QStandardItem(str(pick.resource_id)) # add a checkbox to it item.setCheckable(True) item.setEditable(False) item.setTristate(True) # Add the item to the model model.appendRow(item) # Apply the model to the list view list.setModel(model) # Show the window and run the app list.show() app.exec_()