本文整理汇总了Python中AnyQt.QtWidgets.QListView.setEditTriggers方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.setEditTriggers方法的具体用法?Python QListView.setEditTriggers怎么用?Python QListView.setEditTriggers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QListView
的用法示例。
在下文中一共展示了QListView.setEditTriggers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DiscreteVariableEditor
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setEditTriggers [as 别名]
class DiscreteVariableEditor(VariableEditor):
"""An editor widget for editing a discrete variable.
Extends the :class:`VariableEditor` to enable editing of
variables values.
"""
def setup_gui(self):
layout = QVBoxLayout()
self.setLayout(layout)
self.main_form = QFormLayout()
self.main_form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
layout.addLayout(self.main_form)
self._setup_gui_name()
self._setup_gui_values()
self._setup_gui_labels()
def _setup_gui_values(self):
self.values_edit = QListView()
self.values_edit.setEditTriggers(QTreeView.CurrentChanged)
self.values_model = itemmodels.PyListModel(flags=Qt.ItemIsSelectable | \
Qt.ItemIsEnabled | Qt.ItemIsEditable)
self.values_edit.setModel(self.values_model)
self.values_model.dataChanged.connect(self.on_values_changed)
self.main_form.addRow("Values:", self.values_edit)
def set_data(self, var):
"""Set the variable to edit
"""
VariableEditor.set_data(self, var)
self.values_model[:] = list(var.values) if var is not None else []
def get_data(self):
"""Retrieve the modified variable
"""
name = str(self.name_edit.text())
labels = self.labels_model.get_dict()
values = map(str, self.values_model)
if self.var is not None and not self.is_same():
var = type(self.var)(name, values=values)
var.attributes.update(labels)
self.var = var
else:
var = self.var
return var
def is_same(self):
"""Is the current model state the same as the input.
"""
values = list(map(str, self.values_model))
return (VariableEditor.is_same(self) and self.var is not None and
self.var.values == values)
def clear(self):
"""Clear the model state.
"""
VariableEditor.clear(self)
self.values_model.wrap([])
@Slot()
def on_values_changed(self):
self.maybe_commit()