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. a question dropEvent: mouse event freeze when modal window show
Qt 6.11 is out! See what's new in the release blog

a question dropEvent: mouse event freeze when modal window show

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 300 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    AA130
    wrote on last edited by
    #1

    the simple code like follow:

    import sys
    
    from PyQt5.QtWidgets import QApplication, QDialog, QHBoxLayout, QTreeWidget, QTreeWidgetItem, QMessageBox
    from PyQt5.QtCore import QTimer
    
    
    def timeout():
    	msg = QMessageBox(QMessageBox.Warning, "title", "66666")
    	msg.exec()
    
    
    def run():
    	qapp = QApplication(sys.argv)
    
    	timer = QTimer()
    	timer.setSingleShot(True)
    	timer.timeout.connect(timeout)
    	timer.start(3000)
    
    	tree = QTreeWidget()
    	items = []
    	items.append(QTreeWidgetItem(None, ["111"]))
    	items.append(QTreeWidgetItem(None, ["222"]))
    	items.append(QTreeWidgetItem(None, ["333"]))
    	items.append(QTreeWidgetItem(None, ["444"]))
    
    	tree.setSelectionMode(QTreeWidget.ExtendedSelection)
    	tree.setHeaderLabels(["Name"])
    	tree.setDragEnabled(True)
    	tree.setAcceptDrops(True)
    	tree.insertTopLevelItems(0, items)
    
    	layout = QHBoxLayout()
    	layout.addWidget(tree)
    
    	dlg = QDialog()
    	dlg.setLayout(layout)
    	dlg.show()
    
    	sys.exit(qapp.exec_())
    
    
    if __name__ == "__main__":
    	run()
    
    

    Animation222.gif

    drag one of item and keep pressing the mouse left button, when the messagebox shown the program will be freeze

    I known the modal window will blocking the event loop, my question is have a solution to cancel the drop event before the modal window show?

    my env:
    windows 10
    python 3.6.8
    pyqt 5.13.0

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One possible alternative could be to use QMessageBox::open in place of exec.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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