本文整理汇总了Python中AnyQt.QtWidgets.QLineEdit.installEventFilter方法的典型用法代码示例。如果您正苦于以下问题:Python QLineEdit.installEventFilter方法的具体用法?Python QLineEdit.installEventFilter怎么用?Python QLineEdit.installEventFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.installEventFilter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OWSelectAttributes
# 需要导入模块: from AnyQt.QtWidgets import QLineEdit [as 别名]
# 或者: from AnyQt.QtWidgets.QLineEdit import installEventFilter [as 别名]
class OWSelectAttributes(widget.OWWidget):
name = "Select Columns"
description = "Select columns from the data table and assign them to " \
"data features, classes or meta variables."
icon = "icons/SelectColumns.svg"
priority = 100
inputs = [("Data", Table, "set_data")]
outputs = [("Data", Table), ("Features", widget.AttributeList)]
want_main_area = False
want_control_area = True
settingsHandler = SelectAttributesDomainContextHandler()
domain_role_hints = ContextSetting({})
auto_commit = Setting(False)
def __init__(self):
super().__init__()
self.controlArea = QWidget(self.controlArea)
self.layout().addWidget(self.controlArea)
layout = QGridLayout()
self.controlArea.setLayout(layout)
layout.setContentsMargins(4, 4, 4, 4)
box = gui.vBox(self.controlArea, "Available Variables",
addToLayout=False)
self.filter_edit = QLineEdit()
self.filter_edit.setToolTip("Filter the list of available variables.")
box.layout().addWidget(self.filter_edit)
if hasattr(self.filter_edit, "setPlaceholderText"):
self.filter_edit.setPlaceholderText("Filter")
self.completer = QCompleter()
self.completer.setCompletionMode(QCompleter.InlineCompletion)
self.completer_model = QStringListModel()
self.completer.setModel(self.completer_model)
self.completer.setModelSorting(
QCompleter.CaseSensitivelySortedModel)
self.filter_edit.setCompleter(self.completer)
self.completer_navigator = CompleterNavigator(self)
self.filter_edit.installEventFilter(self.completer_navigator)
def dropcompleted(action):
if action == Qt.MoveAction:
self.commit()
self.available_attrs = VariableListModel(enable_dnd=True)
self.available_attrs_proxy = VariableFilterProxyModel()
self.available_attrs_proxy.setSourceModel(self.available_attrs)
self.available_attrs_view = VariablesListItemView(
acceptedType=Orange.data.Variable)
self.available_attrs_view.setModel(self.available_attrs_proxy)
aa = self.available_attrs
aa.dataChanged.connect(self.update_completer_model)
aa.rowsInserted.connect(self.update_completer_model)
aa.rowsRemoved.connect(self.update_completer_model)
self.available_attrs_view.selectionModel().selectionChanged.connect(
partial(self.update_interface_state, self.available_attrs_view))
self.available_attrs_view.dragDropActionDidComplete.connect(dropcompleted)
self.filter_edit.textChanged.connect(self.update_completer_prefix)
self.filter_edit.textChanged.connect(
self.available_attrs_proxy.set_filter_string)
box.layout().addWidget(self.available_attrs_view)
layout.addWidget(box, 0, 0, 3, 1)
box = gui.vBox(self.controlArea, "Features", addToLayout=False)
self.used_attrs = VariableListModel(enable_dnd=True)
self.used_attrs_view = VariablesListItemView(
acceptedType=(Orange.data.DiscreteVariable,
Orange.data.ContinuousVariable))
self.used_attrs_view.setModel(self.used_attrs)
self.used_attrs_view.selectionModel().selectionChanged.connect(
partial(self.update_interface_state, self.used_attrs_view))
self.used_attrs_view.dragDropActionDidComplete.connect(dropcompleted)
box.layout().addWidget(self.used_attrs_view)
layout.addWidget(box, 0, 2, 1, 1)
box = gui.vBox(self.controlArea, "Target Variable", addToLayout=False)
self.class_attrs = ClassVarListItemModel(enable_dnd=True)
self.class_attrs_view = ClassVariableItemView(
acceptedType=(Orange.data.DiscreteVariable,
Orange.data.ContinuousVariable))
self.class_attrs_view.setModel(self.class_attrs)
self.class_attrs_view.selectionModel().selectionChanged.connect(
partial(self.update_interface_state, self.class_attrs_view))
self.class_attrs_view.dragDropActionDidComplete.connect(dropcompleted)
self.class_attrs_view.setMaximumHeight(24)
box.layout().addWidget(self.class_attrs_view)
layout.addWidget(box, 1, 2, 1, 1)
box = gui.vBox(self.controlArea, "Meta Attributes", addToLayout=False)
self.meta_attrs = VariableListModel(enable_dnd=True)
self.meta_attrs_view = VariablesListItemView(
acceptedType=Orange.data.Variable)
self.meta_attrs_view.setModel(self.meta_attrs)
self.meta_attrs_view.selectionModel().selectionChanged.connect(
#.........这里部分代码省略.........
示例2: variables_filter
# 需要导入模块: from AnyQt.QtWidgets import QLineEdit [as 别名]
# 或者: from AnyQt.QtWidgets.QLineEdit import installEventFilter [as 别名]
def variables_filter(model, parent=None, accepted_type=Orange.data.Variable,
view_type=VariablesListItemView):
"""
GUI components: ListView with a lineedit which works as a filter. One can write
a variable name in a edit box and possible matches are then shown in a listview.
"""
def update_completer_model():
""" This gets called when the model for available attributes changes
through either drag/drop or the left/right button actions.
"""
nonlocal original_completer_items
items = ["%s=%s" % item for v in model for item in v.attributes.items()]
new = sorted(set(items))
if new != original_completer_items:
original_completer_items = new
completer_model.setStringList(original_completer_items)
def update_completer_prefix():
""" Prefixes all items in the completer model with the current
already done completion to enable the completion of multiple keywords.
"""
nonlocal original_completer_items
prefix = str(completer.completionPrefix())
if not prefix.endswith(" ") and " " in prefix:
prefix, _ = prefix.rsplit(" ", 1)
items = [prefix + " " + item
for item in original_completer_items]
else:
items = original_completer_items
old = list(map(str, completer_model.stringList()))
if set(old) != set(items):
completer_model.setStringList(items)
original_completer_items = []
filter_edit = QLineEdit()
filter_edit.setToolTip("Filter the list of available variables.")
filter_edit.setPlaceholderText("Filter")
completer_model = QStringListModel()
completer = QCompleter(completer_model, filter_edit)
completer.setCompletionMode(QCompleter.InlineCompletion)
completer.setModelSorting(QCompleter.CaseSensitivelySortedModel)
filter_edit.setCompleter(completer)
completer_navigator = CompleterNavigator(parent)
filter_edit.installEventFilter(completer_navigator)
proxy = VariableFilterProxyModel()
proxy.setSourceModel(model)
view = view_type(acceptedType=accepted_type)
view.setModel(proxy)
model.dataChanged.connect(update_completer_model)
model.rowsInserted.connect(update_completer_model)
model.rowsRemoved.connect(update_completer_model)
filter_edit.textChanged.connect(update_completer_prefix)
filter_edit.textChanged.connect(proxy.set_filter_string)
return filter_edit, view