我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用PySide.QtGui.QStandardItem()。
def addItem(self, mitem, data=None, checked=False): item = QtGui.QStandardItem() item.setData(mitem, QtCore.Qt.DisplayRole) if data is not None: item.setData(data, QtCore.Qt.UserRole) item.setEditable(self.renameEnabled) item.setDropEnabled(False) item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) item.setCheckState(QtCore.Qt.Unchecked if not checked else QtCore.Qt.Checked) # Can be used to store data linked to the name # item.setData(customData, QtCore.Qt.UserRole) self.item_list_model.appendRow(item) self.item_count += 1
def array_to_model(self, array): model = QtGui.QStandardItemModel() parentItem = model.invisibleRootItem() for ntuple in array: tag = ntuple[0] value = ntuple[1] if isinstance(value, dict): self.recurse_dic_to_item(value, parentItem) else: item = QtGui.QStandardItem(tag + str(value)) parentItem.appendRow(item) return parentItem
def recurse_dic_to_item(self, dic, parent): for k in dic: v = dic[k] if isinstance(v, dict): item = QtGui.QStandardItem(k + ':' + str(v)) parent.appendRow(self.recurse_dic_to_item(v, item)) else: item = QtGui.QStandardItem(k + ': ' + str(v)) parent.appendRow(item) return parent
def __init__(self, parent=None, win=None, xrefs=None): super(XrefListView, self).__init__(parent) self.setMinimumSize(600, 400) #TODO: adjust window depending on text displayed self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) self.mainwin = win self.parent = parent self.doubleClicked.connect(self.doubleClickedHandler) model = QtGui.QStandardItemModel(self) for x in xrefs: item = QtGui.QStandardItem(x) model.appendRow(item) self.setModel(model)