Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在pyqt中捕获QtableWidget中的drop事件_Python_Drag And Drop_Pyqt_Pyqt4_Qtablewidget - Fatal编程技术网

Python 如何在pyqt中捕获QtableWidget中的drop事件

Python 如何在pyqt中捕获QtableWidget中的drop事件,python,drag-and-drop,pyqt,pyqt4,qtablewidget,Python,Drag And Drop,Pyqt,Pyqt4,Qtablewidget,我有一个窗口,其中包含3个使用Qt Designer设计的表小部件 表1。显示存在的组的步骤 表2。显示所有员工(将启用的设置拖到True) 表3。显示所选组中的员工(设置为True) 我想看一下表3上的下降事件。也就是说,在执行drop之后,我想运行一个函数。同时,它应该避免在下降重复 我设置了事件过滤器 Table3.installEventFilter(self) 但没能抓住掉球事件 我的eventfilter def如下所示 def eventFilter(self, object,

我有一个窗口,其中包含3个使用Qt Designer设计的表小部件

表1。显示存在的组的步骤

表2。显示所有员工(将启用的设置拖到True)

表3。显示所选组中的员工(设置为True)

我想看一下表3上的下降事件。也就是说,在执行drop之后,我想运行一个函数。同时,它应该避免在下降重复

我设置了事件过滤器

Table3.installEventFilter(self)
但没能抓住掉球事件

我的eventfilter def如下所示

def eventFilter(self, object, event):
    if (object is self.TBLW_GroupMembers):
        if (event.type() == QtCore.QEvent.DragEnter):
            if event.mimeData().hasUrls():
                event.accept()   # must accept the dragEnterEvent or else the dropEvent can't occur !!!
                print "accept"
            else:
                event.ignore()
                print "ignore"
        if (event.type() == QtCore.QEvent.Drop):
            print 'drop'
        return False # lets the event continue to the edit
    return False
我已经遵循了这个过程张贴在这个网站上


能够捕获
DragEnter
但不能
Drop
我相信您还需要处理(并接受)
QtCore.QEvent.DragMove
事件。您可能还应该为
DragLeave
添加一个处理程序,但我认为这不太重要

不幸的是,这个需求似乎没有很好的文档化,但我在实现拖放时观察到了类似的行为。就我个人而言,我通常只覆盖相关小部件的
dragEnterEvent()
dragmovevent()
dropEvent()
方法(而不是安装事件过滤器),但原理是相同的(因此我希望解决方案是相同的)