示例#1
0
 def eventFilter(self, obj: QObject, event: QEvent):
     if obj.objectName() == "lineEdit":
         if event.type() == QEvent.DragEnter:
             new_method.lineEdit_dragEnterEvent(event)
             return True
         if event.type() == QEvent.Drop:
             new_method.lineEdit_dropEvent(self, event)
             return True
     return QObject.eventFilter(self, obj, event)
示例#2
0
def find_ancestor(obj: QObject, type: str = "", name: str = ""):
    """Returns the closest ancestor of obj with type and name given"""
    obj = obj.parent()
    if not obj:
        return None
    # used recursion here before but pyside
    # deleted the object before returning
    while not ((name == "" or obj.objectName() == name) and
               (type == "" or obj.metaObject().className() == str(type))):
        obj = obj.parent()
    return obj