本文整理汇总了Python中PyQt5.QtGui.QStandardItem类的典型用法代码示例。如果您正苦于以下问题:Python QStandardItem类的具体用法?Python QStandardItem怎么用?Python QStandardItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QStandardItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_item
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__
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: __connect_events
def __connect_events(self):
self.model = QStandardItemModel()
self.mass_list = []
for i in range(10):
mass = 184 + i
self.mass_list.append(str(mass))
for i in range(10):
mass = 209 + i
self.mass_list.append(str(mass))
for i in range(10):
mass = 273.3 + i
self.mass_list.append(str(mass))
for i in range(10):
mass = 294 + i
self.mass_list.append(str(mass))
for mass in self.mass_list:
item = QStandardItem(mass)
item.setCheckable(True)
item.setEditable(True)
self.model.appendRow(item)
self.view = self.ui.listView_Mass
self.view.setModel(self.model)
# changes in one item, don't know which one
self.model.itemChanged.connect(self.change_list)
# changes in button
self.ui.pushButton_ChangeList.clicked.connect(self.emit_list_signal)
# get peaks found and update automatically the mass list
self.ana.masstabSelectorRaisedSignal.connect(self.update_list_view)
示例4: initUi
def initUi(self, options, enabledOptions, headerOptions, singleSelectionMode):
boldFont = QFont()
boldFont.setBold(True)
# set the selection mode
if not singleSelectionMode:
self.listView_options.setSelectionMode(QAbstractItemView.ExtendedSelection)
# create enableItems if none
if enabledOptions is None:
enabledOptions = [True for idx in range(len(options))]
# Insert the choices
self.standaredItemModel = QStandardItemModel(self.listView_options)
self.standaredItemModel.itemChanged.connect(self.onItemChanged)
for idx in range(len(options)):
standaredItem = QStandardItem(options[idx])
standaredItem.setSelectable(enabledOptions[idx])
if idx in headerOptions:
standaredItem.setFont(boldFont)
self.standaredItemModel.appendRow(standaredItem)
self.listView_options.setModel(self.standaredItemModel)
# disable select all / de select all buttons if in single selection
# mode
if singleSelectionMode:
self.pushButton_sellectAll.setDisabled(True)
self.pushButton_deSellectAll.setDisabled(True)
示例5: __init__
def __init__(self, parent=None):
super(UniverseTreeView, self).__init__(parent)
model = QStandardItemModel()
self.setModel(model)
root_item = model.invisibleRootItem()
self.areas_item = QStandardItem("Areas")
self.areas_item.setData(Areas, Qt.UserRole)
self.areas_item.setEditable(False)
root_item.appendRow(self.areas_item)
Areas.added.connect(self.init_areas)
Areas.removed.connect(self.init_areas)
Areas.reset.connect(self.init_areas)
self.characters_item = QStandardItem("Characters")
self.characters_item.setData(Characters, Qt.UserRole)
self.characters_item.setEditable(False)
root_item.appendRow(self.characters_item)
Characters.added.connect(self.init_characters)
Characters.removed.connect(self.init_characters)
Characters.reset.connect(self.init_characters)
self.races_item = QStandardItem("Races")
self.races_item.setEditable(False)
self.races_item.setData(Races, Qt.UserRole)
root_item.appendRow(self.races_item)
Races.added.connect(self.init_races)
Races.removed.connect(self.init_races)
Races.reset.connect(self.init_races)
self.item_prototypes_item = QStandardItem("Item Prototypes")
self.item_prototypes_item.setData(ItemPrototypes, Qt.UserRole)
self.item_prototypes_item.setEditable(False)
root_item.appendRow(self.item_prototypes_item)
ItemPrototypes.added.connect(self.init_item_prototypes)
ItemPrototypes.removed.connect(self.init_item_prototypes)
ItemPrototypes.reset.connect(self.init_item_prototypes)
self.groups_item = QStandardItem("Groups")
self.groups_item.setData(Groups, Qt.UserRole)
self.groups_item.setEditable(False)
root_item.appendRow(self.groups_item)
Groups.added.connect(self.init_groups)
Groups.removed.connect(self.init_groups)
Groups.reset.connect(self.init_groups)
self.init_all()
self.activated.connect(self.item_activated)
示例6: test_completion_show
def test_completion_show(show, rows, quick_complete, completionview,
config_stub):
"""Test that the completion widget is shown at appropriate times.
Args:
show: The completion show config setting.
rows: Each entry represents a completion category with only one item.
quick_complete: The completion quick-complete config setting.
"""
config_stub.data['completion']['show'] = show
config_stub.data['completion']['quick-complete'] = quick_complete
model = base.BaseCompletionModel()
for name in rows:
cat = QStandardItem()
model.appendRow(cat)
cat.appendRow(QStandardItem(name))
filtermodel = sortfilter.CompletionFilterModel(model,
parent=completionview)
assert not completionview.isVisible()
completionview.set_model(filtermodel)
assert completionview.isVisible() == (show == 'always' and len(rows) > 0)
completionview.completion_item_focus('next')
expected = (show != 'never' and len(rows) > 0 and
not (quick_complete and len(rows) == 1))
assert completionview.isVisible() == expected
completionview.set_model(None)
completionview.completion_item_focus('next')
assert not completionview.isVisible()
示例7: test_completion_item_next_prev
def test_completion_item_next_prev(tree, count, expected, completionview):
"""Test that on_next_prev_item moves the selection properly.
Args:
tree: Each list represents a completion category, with each string
being an item under that category.
count: Number of times to go forward (or back if negative).
expected: item data that should be selected after going back/forward.
"""
model = base.BaseCompletionModel()
for catdata in tree:
cat = QStandardItem()
model.appendRow(cat)
for name in catdata:
cat.appendRow(QStandardItem(name))
filtermodel = sortfilter.CompletionFilterModel(model,
parent=completionview)
completionview.set_model(filtermodel)
if count < 0:
for _ in range(-count):
completionview.completion_item_prev()
else:
for _ in range(count):
completionview.completion_item_next()
idx = completionview.selectionModel().currentIndex()
assert filtermodel.data(idx) == expected
示例8: populate
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])
])
示例9: addPoint
def addPoint(self):
rows = self._current.editor.selectedRows()
newStart = self._videoWidget.position
if len(rows) == 0 or newStart is None:
self._err.showMessage(_("Select a subtitle and position in current video first."))
return
# row and sub reflect the same subtitle, but we need both for different things
row = rows[0]
sub = self._current.data.subtitles[row]
# Don't add the same subtitle or the same sync time twice
if any(row == point.subNo or newStart == point.start
for point in _syncPoints(self._current.model)):
self._err.showMessage(_("Can't repeat synchronization points"))
return
if sub.fps != newStart.fps:
self._err.showMessage(_("Subtitle and video have different framerates (%(sub)s vs"
"%(vid)s") % dict(sub=sub.fps, vid=newStart.fps))
return
delta = sub.end - sub.start
newEnd = newStart + delta
startItem, endItem, textItem = createRow(sub, newStart, newEnd)
subNoItem = QStandardItem(str(row))
subNoItem.setEditable(False)
textItem.setEditable(False)
rmItem = QStandardItem("")
self._current.model.appendRow([subNoItem, startItem, endItem, textItem, rmItem])
self._rmButton(self._table, rmItem)
示例10: test_completion_item_focus
def test_completion_item_focus(which, tree, expected, completionview, qtbot):
"""Test that on_next_prev_item moves the selection properly.
Args:
which: the direction in which to move the selection.
tree: Each list represents a completion category, with each string
being an item under that category.
expected: expected argument from on_selection_changed for each
successive movement. None implies no signal should be
emitted.
"""
model = base.BaseCompletionModel()
for catdata in tree:
cat = QStandardItem()
model.appendRow(cat)
for name in catdata:
cat.appendRow(QStandardItem(name))
filtermodel = sortfilter.CompletionFilterModel(model,
parent=completionview)
completionview.set_model(filtermodel)
for entry in expected:
if entry is None:
with qtbot.assertNotEmitted(completionview.selection_changed):
completionview.completion_item_focus(which)
else:
with qtbot.waitSignal(completionview.selection_changed) as sig:
completionview.completion_item_focus(which)
assert sig.args == [entry]
示例11: current_to_recent
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)
示例12: fillReferences
def fillReferences(self):
for value in self.referenceList:
item = QStandardItem(value[0])
check = Qt.Checked if value[1] else Qt.Unchecked
item.setCheckState(check)
item.setCheckable(True)
self.referenceListModel.appendRow(item)
示例13: set_server_mgr
def set_server_mgr(self, server_mgr):
self.server_mgr = server_mgr
self.nodesets = []
self.model.clear()
self.model.setHorizontalHeaderLabels(['Node Sets'])
item = QStandardItem("Opc.Ua.NodeSet2.xml")
item.setFlags(Qt.NoItemFlags)
self.model.appendRow([item])
self.view.expandAll()
示例14: init
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)
示例15: __init__
def __init__(self,xpos=0.0,ypos=0.0,zpos=0.0):
QStandardItem.__init__(self,"X: "+str(xpos)+" Y: "+str(ypos)+" Z: "+str(zpos))
try:
self.x=float(xpos)
self.y=float(ypos)
self.z=float(zpos)
except ValueError:
#raise
raise ValueError("could not set point values")