From: Olivier A. <oli...@li...> - 2005-12-08 16:04:01
|
Hi, I've got a problem which Qt which occurs only on OSX. The cursor isn't always refreshed on drag and drops. example: Take tree fields in a horizontal layout. Left and Right fields are dragable while the field of the middle isn't. The mouse cursor change for the forbiden cursor while the mouse is over the middle field which is ok. But when I leave this field for the right one, the cursor should change to the drop enabled one. I try to override the cursor during Drag and Drop, but that don't work better. I join the code of the example below. ---- # -*- coding: utf-8 -*- """ Prototype of Drag And Drop """ from qt import * import sys, os class ProjectView(QListBox): def __init__(self, parent = None, name = None): super(ProjectView, self).__init__(parent, name) self.viewport().setAcceptDrops(True) self.setAcceptDrops(True) def contentsMousePressEvent(self, event): if event.button() == Qt.LeftButton: self.dragPos = QPoint(event.pos()) QListBox.contentsMousePressEvent(self, event) def contentsMouseMoveEvent(self, event): if event.state() and Qt.LeftButton: distance = (event.pos() - self.dragPos).manhattanLength() print event.pos().x() print self.dragPos.x() print (event.pos()-self.dragPos).x() if distance > QApplication.startDragDistance(): print "start drag" self.startDrag() #else: # print "only %s for %s" % (distance, QApplication.startDragDistance()) QListBox.contentsMouseMoveEvent(self,event) def startDrag(self): person = self.currentText() if not person.isEmpty(): drag = QTextDrag(person, self) drag.setSubtype("x-person") drag.drag() def contentsDragEnterEvent(self, event): QApplication.restoreOverrideCursor() event.accept(event.provides("text/x-person")) def contentsDropEvent(self, event): person = QString() if QTextDrag.decode(event, person): fromWidget = event.source() if fromWidget and fromWidget != self and fromWidget.inherits("ProjectView"): fromProject = fromWidget item = fromProject.findItem(person, Qt.ExactMatch) fromProject.removeItem(fromProject.index(item)) self.insertItem(person) QApplication.restoreOverrideCursor() class MainWindow(QMainWindow): def __init__(self, parent=None, name=None): super(MainWindow, self).__init__() self.setCaption(self.tr("Drag Person")) self.PFrom = ProjectView(self, "From") self.bigArea = QListBox(self, "No") self.bigArea.setAcceptDrops(False) self.PTo = ProjectView(self, "To") self.layout = QVBoxLayout(self) self.layout.addWidget(self.PFrom) self.layout.addWidget(self.bigArea) self.layout.addWidget(self.PTo) self.PFrom.insertItem("Vincent") self.PFrom.insertItem("Olivier") self.PFrom.insertItem("Yann") self.bigArea.insertItem("You can't drop here --> OS X display a forbidden cursor") self.PTo.insertItem("Drop here --> BUG: OS X display a forbidden cursor") self.setAcceptDrops(True) def dragEnterEvent(self, event): event.accept(QUriDrag.canDecode(event)) if __name__ == "__main__": a = QApplication(sys.argv) QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()")) w = MainWindow() a.setMainWidget(w) w.show() a.exec_loop() |