内容简介:翻译自:https://stackoverflow.com/questions/1224432/how-do-i-respond-to-an-internal-drag-and-drop-operation-using-a-qlistwidget
我有一个Qt4应用程序(使用PyQt绑定),其中包含一个QListWidget,初始化如下:
class MyList(QtGui.QListWidget): def __init__(self): QtGui.QListWidget.__init__(self) self.setDragDropMode(self.InternalMove)
我可以添加项目,这允许我拖放以重新 排序 列表.但是如何在用户重新排序列表时收到通知?我尝试将dropMimeData(self,index,data,action)方法添加到类中,但它永远不会被调用.
我只是不得不处理这个问题,这是一个痛苦的屁股,但这是做什么的:
您必须在ListWidget子类上安装eventFilter,然后监视ChildRemoved事件.此事件包括移动和移除,因此它应该用于通过拖放在列表中重新排列项目.
我在C中写了我的Qt,但这是一个pythonification版本:
class MyList(QtGui.QListWidget): def __init__(self): QtGui.QListWidget.__init__(self) self.setDragDropMode(self.InternalMove) self.installEventFilter(self) def eventFilter(self, sender, event): if (event.type() == QEvent.ChildRemoved): self.on_order_changed() return False # don't actually interrupt anything def on_order_changed(self): # do magic things with our new-found knowledge
如果您有一些包含此列表的其他类,您可能希望在那里移动事件过滤器方法.希望这会有所帮助,我知道在解决这个问题之前,我必须与之斗争一天.
翻译自:https://stackoverflow.com/questions/1224432/how-do-i-respond-to-an-internal-drag-and-drop-operation-using-a-qlistwidget
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Struts 2 in Action
Don Brown、Chad Davis、Scott Stanlick / Manning Publications / 2008.3 / $44.99
The original Struts project revolutionized Java web development and its rapid adoption resulted in the thousands of Struts-based applications deployed worldwide. Keeping pace with new ideas and trends......一起来看看 《Struts 2 in Action》 这本书的介绍吧!