[英]Python: capture re-ordering event in a QListWidget?
我需要響應QListWidget中項目的拖放重新排序。 我找不到要使用的QEvent。 任何幫助,將不勝感激!
我正在使用eventFilter例程來捕獲GUI中的事件:
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def eventFilter(self, sourceObj, event):
if event.type()== QtCore.QEvent.Drop:
print("got to drop event")
(processing code here)
也許這個事件不會觸發項目的拖放重新排序,因為拖放是窗口小部件的內部(例如,窗口小部件外部沒有任何內容被丟棄)?
我已經嘗試過QtCore.QEvent.Drop
和QtCore.QEvent.MouseButtonRelease
但沒有成功。 我應該使用哪個活動?
(我在Ubuntu 16.10上使用Python3,PyQt4。我的eventFilter例程適用於GUI中的其他操作,如clicks,lostFocus等)
這是我發現的解決方案。 解決方案是使用eventFilter來監聽ChildRemoved QEvent。 顯然,當QListWidget中的項目通過拖放重新排序時,QT會觸發此事件。
步驟1.在包含QListWidget的類的init (self)中,為要捕獲其事件的窗口小部件安裝事件過濾器。
def __init__(self):
self.lstYourWidgetNameHere.installEventFilter(self)
步驟2.在同一個類的eventFilter例程中,檢查ChildRemoved QEvent。
def eventFilter(self, sourceObj, event):
objName = str(sourceObj.objectName())
if event.type()== QtCore.QEvent.ChildRemoved:
if objName == "lstYourWidgetNameHere":
(your code here)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.