Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDragLeaveEvent called while mouse still in widget

QDragLeaveEvent called while mouse still in widget

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 604 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stirfoo
    wrote on last edited by
    #1

    When implementing drag and drop within a QListWidget, a spurious QDragLeaveEvent is fired while the mouse is still in the widget. If you run this program it should print mouse and drag/drop events. You may have to start a drag, then stop dragging but don't release the mouse. Then, move the mouse again.

    @
    import sys
    from PyQt4.QtGui import *
    from PyQt4.QtCore import *
    from PyQt4.QtCore import Qt as qt

    class ListView(QListWidget):
    def init(self):
    super(ListView, self).init()
    self.setAcceptDrops(True)
    def dragEnterEvent(self, e):
    print 'dragEnterEvent'
    if e.mimeData().hasFormat('text/plain'):
    e.acceptProposedAction()
    def dragLeaveEvent(self, e):
    ###############################################################
    # This gets called while the mouse is still within the widget #
    ###############################################################
    print 'dragLeaveEvent'
    def dragMoveEvent(self, e):
    print 'dragMoveEvent'
    e.acceptProposedAction()
    def dropEvent(self, e):
    print 'dropEvent'
    text = e.mimeData().text()
    item = QListWidgetItem(text)
    self.insertItem(0, item)
    e.acceptProposedAction()
    def mousePressEvent(self, e):
    print 'mousePressEvent'
    if e.button() == qt.LeftButton:
    self.downPos = e.pos()
    super(ListView, self).mousePressEvent(e)
    def mouseMoveEvent(self, e):
    print 'mouseMoveEvent'
    if e.buttons() != qt.LeftButton:
    return
    if self.currentItem() is None:
    return
    if self.itemAt(self.downPos) != self.currentItem():
    return
    dragDist = (e.pos() - self.downPos).manhattanLength()
    if dragDist < QApplication.startDragDistance():
    return
    drag = QDrag(self)
    mimeData = QMimeData()
    mimeData.setText(self.currentItem().text())
    drag.setMimeData(mimeData)
    self.takeItem(self.currentRow())
    drag.exec_(qt.MoveAction)

    if name == 'main':
    app = QApplication(sys.argv)
    v = ListView()
    v.insertItem(0, QListWidgetItem("Foo"))
    v.show()
    app.exec_()
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved