Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

a question dropEvent: mouse event freeze when modal window show



  • 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


  • Lifetime Qt Champion

    Hi,

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


Log in to reply