本文整理汇总了Python中PyQt5.QtGui.QStandardItem.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QStandardItem.setData方法的具体用法?Python QStandardItem.setData怎么用?Python QStandardItem.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QStandardItem
的用法示例。
在下文中一共展示了QStandardItem.setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_item
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def new_item(self, cat, name, desc='', misc=None, sort=None,
userdata=None):
"""Add a new item to a category.
Args:
cat: The parent category.
name: The name of the item.
desc: The description of the item.
misc: Misc text to display.
sort: Data for the sort role (int).
userdata: User data to be added for the first column.
Return:
A (nameitem, descitem, miscitem) tuple.
"""
assert not isinstance(name, int)
assert not isinstance(desc, int)
assert not isinstance(misc, int)
nameitem = QStandardItem(name)
descitem = QStandardItem(desc)
if misc is None:
miscitem = QStandardItem()
else:
miscitem = QStandardItem(misc)
cat.appendRow([nameitem, descitem, miscitem])
if sort is not None:
nameitem.setData(sort, Role.sort)
if userdata is not None:
nameitem.setData(userdata, Role.userdata)
return nameitem, descitem, miscitem
示例2: __init__
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def __init__(self, database, main_spectrum = None):
super(ReferenceSpectraDialog, self).__init__()
self.main_spectrum = main_spectrum
self.ui = Ui_ReferenceSpectraDialog()
self.ui.setupUi(self)
self.reference_catalogues = ReferenceCatalogues(database)
self.full_model = QStandardItemModel()
self.catalogues_model = QStandardItemModel()
self.ui.catalogue.setModel(self.catalogues_model)
self.ui.catalogue.currentTextChanged.connect(lambda txt: self.populate())
for catname, cat in self.reference_catalogues.catalogues.items():
row = QStandardItem(catname)
row.setData(cat)
self.catalogues_model.appendRow(row)
self.model = QSortFilterProxyModel()
self.model.setSourceModel(self.full_model)
self.model.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.model.setFilterKeyColumn(0)
self.ui.entries.setModel(self.model)
self.ui.type_filter.currentTextChanged.connect(lambda txt: self.model.setFilterWildcard("{}*".format(txt) ) )
self.ui.buttonBox.button(QDialogButtonBox.Open).setEnabled(False)
self.ui.entries.selectionModel().selectionChanged.connect(lambda selected, deselected: self.ui.buttonBox.button(QDialogButtonBox.Open).setEnabled(len(selected.indexes()) > 0) )
self.accepted.connect(self.load_fits)
self.populate()
示例3: populate
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def populate(self):
self.model.clear()
self.model.setHorizontalHeaderLabels(['Lambda', 'Element', 'Atomic number', 'Ionization', 'Stellar spectral types'])
c = self.database.cursor()
query = "SELECT lambda, Element, Z, Ion, SpTypes from spectral_lines WHERE {} ORDER BY lambda ASC;"
conditions = ['(1 = 1)']
element = self.elements_model.item(self.ui.elements.currentIndex()).data()
if element['z']:
conditions.append("(Z = {})".format(element['z']))
if self.ui.lambda_from.value() > 0:
conditions.append("(Lambda >= {})".format(self.ui.lambda_from.value()))
if self.ui.lambda_to.value() > 0:
conditions.append("(Lambda <= {})".format(self.ui.lambda_to.value()))
if self.ui.name.text():
conditions.append("(Element like '%{}%')".format(self.ui.name.text()))
if self.ui.sp_types.isChecked():
conditions.append("(SpTypes <> '')")
for row in c.execute(query.format(" AND ".join(conditions))):
first_item = QStandardItem("{}".format(row[0]))
first_item.setData({'lambda': row[0], 'name': row[1], 'z': row[2]})
self.model.appendRow( [
first_item,
QStandardItem(row[1]),
QStandardItem("{}".format(row[2])),
QStandardItem("{}".format(row[3])),
QStandardItem(row[4])
])
示例4: _show_attrs
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def _show_attrs(self):
attrs = self.get_all_attrs()
self.model.setHorizontalHeaderLabels(['Attribute', 'Value', 'DataType'])
for attr, dv in attrs:
if attr == ua.AttributeIds.DataType:
string = data_type_to_string(dv)
elif attr in (ua.AttributeIds.AccessLevel,
ua.AttributeIds.UserAccessLevel,
ua.AttributeIds.WriteMask,
ua.AttributeIds.UserWriteMask,
ua.AttributeIds.EventNotifier):
attr_name = attr.name
if attr_name.startswith("User"):
attr_name = attr_name[4:]
attr_enum = getattr(ua, attr_name)
string = ", ".join([e.name for e in attr_enum.parse_bitfield(dv.Value.Value)])
else:
string = variant_to_string(dv.Value)
name_item = QStandardItem(attr.name)
vitem = QStandardItem(string)
vitem.setData((attr, dv), Qt.UserRole)
self.model.appendRow([name_item, vitem, QStandardItem(dv.Value.VariantType.name)])
# special case for Value, we want to show timestamps
if attr == ua.AttributeIds.Value:
string = val_to_string(dv.ServerTimestamp)
name_item.appendRow([QStandardItem("Server Timestamp"), QStandardItem(string), QStandardItem(ua.VariantType.DateTime.name)])
string = val_to_string(dv.SourceTimestamp)
name_item.appendRow([QStandardItem("Source Timestamp"), QStandardItem(string), QStandardItem(ua.VariantType.DateTime.name)])
示例5: add_calibration_point_data
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def add_calibration_point_data(self, x_value, wavelength):
x_axis_item = QStandardItem("star" if x_value == 0 else "{}".format(x_value))
x_axis_item.setData(x_value)
wavelength_item = QStandardItem("{:.2f}".format(wavelength))
wavelength_item.setData(wavelength)
self.calibration_model.appendRow([x_axis_item, wavelength_item, QStandardItem("n/a")])
self.spectrum_plot.rm_element('x_axis_pick')
示例6: prev_track
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def prev_track(self):
previous_track = self.recentTrackListModel.takeItem(0)
if previous_track is not None or previous_track is not "":
try:
location = previous_track.data(1)
try:
self.player.stop_item()
print(self.player.get_item())
playing_track = self.player.get_item()
playing_meta = self.meta_info(playing_track)
item = QStandardItem(playing_track)
item.setFlags(item.flags() & ~QtCore.Qt.ItemIsDropEnabled) # This is necessary to drag'n'drop within QueueList
item.setText(playing_meta)
item.setData(playing_track, 1)
self.queueTrackListModel.insertRow(0, item)
print("goes back one step..")
except FileNotFoundError:
print("no current track..")
self.player.set_item(location)
print("loaded: " + self.player.get_item())
self.meta_info(location, active=True)
self.recentTrackListModel.removeRow(0)
print(previous_track.data(0) + " taken back from recent.")
self.play_track()
except AttributeError:
print("nope")
elif previous_track is None or previous_track is "":
print("there's no track - cannot go backwards")
示例7: _show_attrs
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def _show_attrs(self, node):
try:
attrs = self.uaclient.get_all_attrs(node)
except Exception as ex:
self.window.show_error(ex)
raise
self.model.setHorizontalHeaderLabels(['Attribute', 'Value', 'DataType'])
for name, dv in attrs:
if name == "DataType":
if isinstance(dv.Value.Value.Identifier, int) and dv.Value.Value.Identifier < 63:
string = ua.DataType_to_VariantType(dv.Value.Value).name
elif dv.Value.Value.Identifier in ua.ObjectIdNames:
string = ua.ObjectIdNames[dv.Value.Value.Identifier]
else:
string = dv.Value.Value.to_string()
elif name in ("AccessLevel", "UserAccessLevel"):
string = ",".join([e.name for e in ua.int_to_AccessLevel(dv.Value.Value)])
elif name in ("WriteMask", "UserWriteMask"):
string = ",".join([e.name for e in ua.int_to_WriteMask(dv.Value.Value)])
elif name in ("EventNotifier"):
string = ",".join([e.name for e in ua.int_to_EventNotifier(dv.Value.Value)])
else:
string = variant_to_string(dv.Value)
name_item = QStandardItem(name)
vitem = QStandardItem(string)
vitem.setData(dv.Value)
self.model.appendRow([name_item, vitem, QStandardItem(dv.Value.VariantType.name)])
if name == "Value":
string = val_to_string(dv.ServerTimestamp)
name_item.appendRow([QStandardItem("Server Timestamp"), QStandardItem(string), QStandardItem(ua.VariantType.DateTime.name)])
string = val_to_string(dv.SourceTimestamp)
name_item.appendRow([QStandardItem("Source Timestamp"), QStandardItem(string), QStandardItem(ua.VariantType.DateTime.name)])
示例8: current_to_recent
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def current_to_recent(self):
track = self.player.get_item()
if track is not "":
item = QStandardItem(track)
track_meta = self.meta_info(track)
item.setText(track_meta)
item.setData(track, 1)
self.recentTrackListModel.insertRow(0, item)
示例9: init
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def init(self):
model = self.model()
model.clear()
root_item = model.invisibleRootItem()
for t in weapon_types:
item = QStandardItem(t.title())
item.setData(t, Qt.UserRole)
root_item.appendRow(item)
示例10: _set_items
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def _set_items(self, item, data):
item.setRowCount(0)
subitems = []
for d in sorted(data, key=lambda r: r.name.lower()):
subitem = QStandardItem(d.name)
subitem.setEditable(False)
subitem.setData(d, Qt.UserRole)
subitems.append(subitem)
item.appendRows(subitems)
示例11: add_parent_item
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def add_parent_item(self, text):
item = QStandardItem(text)
item.setFlags(item.flags() & ~(Qt.ItemIsEnabled | Qt.ItemIsSelectable))
item.setData("parent", Qt.AccessibleDescriptionRole)
font = item.font()
font.setBold(True)
item.setFont(font)
self.model().appendRow(item)
示例12: init
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def init(self):
print("SelectRaceComboBox.init")
model = self.model()
model.clear()
root_item = model.invisibleRootItem()
for race in Races:
item = QStandardItem(race.name)
item.setData(race, Qt.UserRole)
root_item.appendRow(item)
示例13: _show_list
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def _show_list(self, parent, mylist, vtype):
for idx, val in enumerate(mylist):
name_item = QStandardItem(str(idx))
vitem = QStandardItem()
vitem.setText(val_to_string(val))
vitem.setData(ListData(mylist, idx, val, vtype), Qt.UserRole)
row = [name_item, vitem, QStandardItem(vtype.name)]
parent.appendRow(row)
if vtype == ua.VariantType.ExtensionObject:
self._show_ext_obj(name_item, val)
示例14: AddTag
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def AddTag( self, name ):
newTag = QStandardItem( name )
newTagQuantity = QItemToSortByNum( "0" )
newTag.setFlags( Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsSelectable )
newTag.setData( QVariant( Qt.Unchecked ), Qt.CheckStateRole )
self.tagDict[ name ] = newTag
currentRow = [ newTag, newTagQuantity ]
self.tagNameToTagItemsDict[ name ] = currentRow
self.tagModel.appendRow( currentRow )
self.tagModel.sort( Qt.AscendingOrder )
self.wereAnyChanges = True
示例15: process_track
# 需要导入模块: from PyQt5.QtGui import QStandardItem [as 别名]
# 或者: from PyQt5.QtGui.QStandardItem import setData [as 别名]
def process_track(self, track):
with lock:
start_single = time.time()
item = QStandardItem(track)
item.setFlags(item.flags() & ~QtCore.Qt.ItemIsDropEnabled) # This is necessary to drag'n'drop within QueueList
track_info = self.meta_info(track)
item.setText(track_info)
item.setData(track, 1)
self.queueTrackListModel.appendRow(item)
stop_single = time.time() - start_single
print("queued:", os.path.basename(item.data(0)), "(" + str(stop_single.__round__(5)) + ")" + " --- " + threading.current_thread().name)
if self.player.status is None:
self.get_next_track()