[PyQt] drop action locks up drag source application

Dennis Gidudu dennis.gid at gmail.com
Tue Feb 23 10:14:21 GMT 2010


I'm fairly new to PyQt, so this may be a newbie question, but I just
can't figure it out.

I have a widget that receives drop events from other applications. The
drop event triggers an action that could take quite a lot of time to
finish. I use a modal QProgressDialog to display the progress. Problem
is that the application from which the drag source originated freezes
until the action is completed, making it unusable for several minutes.
Can anyone explain what I am doing wrong? Any help is appreciated.

I'm Running PyQt 4.7 with Python 2.6 on Windows 7.


import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *


class DropperWidget(QLabel):
	
	def __init__(self, *args, **kwargs):
		QLabel.__init__(self, *args, **kwargs)
		
		self.setAcceptDrops(True)
		self.setFixedSize(200, 200)
		self.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
	
	def dragEnterEvent(self, e):
		e.acceptProposedAction()
	
	def dropEvent(self, e):
		e.acceptProposedAction()
		self.emit(SIGNAL('dropped_something()'))


def someLongRunningAction():
	progress_dialog = QProgressDialog('Working...', 'Cancel', 0, 1000000, dropper)
	progress_dialog.setWindowModality(Qt.WindowModal)
	
	while progress_dialog.value() < progress_dialog.maximum() - 1:
		if progress_dialog.wasCanceled():
			break
		
		progress_dialog.setValue(progress_dialog.value() + 1)
	
	progress_dialog.close()


app = QApplication(sys.argv)
dropper = DropperWidget('Drop Stuff Here')
dropper.connect(dropper, SIGNAL('dropped_something()'), someLongRunningAction)
dropper.show()

sys.exit(app.exec_())


More information about the PyQt mailing list