PyQt5 How To Make Drag And Drop Application

In this PyQt5 article i want to show you How To Make Drag And Drop Application, we are

going to create a practical example of Drag and Drop Application in PyQt5.

 

 

 

Also you can check more Python articles in the below links

1: Kivy GUI Development Tutorials

2: Python TKinter GUI Development 

3: Psyide2 GUI Development 

4: wxPython GUI Development 

5: PyQt5 GUI Development Course

 

 

 

 

Drag And Drop

So drag and drop provides a simple visual mechanism which users can use to transfer information between and within applications. Drag and drop is similar in function to the clipboard’s cut and paste mechanism. This document describes the basic drag and drop mechanism and outlines the approach used to enable it in custom controls. Drag and drop operations are also supported by many of Qt’s controls, such as the item views and graphics view framework, as well as editing controls for Qt Widgets and Qt Quick. More information about item views and graphics view is available in Using drag and drop with item views and Graphics View Framework.

 

 

 

Drag and Drop Classes

QDrag Support for MIME-based drag and drop data transfer
QDragEnterEvent Event which is sent to a widget when a drag and drop action enters it
QDragLeaveEvent Event that is sent to a widget when a drag and drop action leaves it
QDragMoveEvent Event which is sent while a drag and drop action is in progress
QDropEvent Event which is sent when a drag and drop action is completed

 

 

 

 

OK now this is the complete code for PyQt5 How To Make Drag And Drop Application.

 

 

 

So in the above code these are our two QListWidgets , and also we have enabled the drag

and drop facility for our two QListWidgets.

 

 

 

 

In here we add items to our two QListWidgets, also make sure that you have some

icons in your working directory.

 

 

 

 

Also every PyQt5 application must create an application object. The sys.argv

parameter is a list of arguments from a command line.

 

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point. The mainloop receives events from the window system and dispatches them to the application widgets. also we have created the object of our Window class.

 

 

 

 

 

So run the complete code and this will be the result

PyQt5 How To Make Drag And Drop Application
PyQt5 How To Make Drag And Drop Application

 

 

 

 

 

Also you can watch the complete video for this article 

Subscribe and Get Free Video Courses & Articles in your Email

 

1 thought on “PyQt5 How To Make Drag And Drop Application”

  1. Easily done with your chosen widgets as they support drag drop event handling natively. This example does not illustrate or demonstrate how one would need to implement the actual properties, actions and events needed for drag drop feature between commonly used and customized objects that typically do not have the complete implementation done out of the box like the widgets in your tutorial. Maybe you could make a tutorial on drag drop that actually demonstrates how it works by coding a drag drop implementation between simple, commonly used widgets?

Comments are closed.

Share via
Copy link
Powered by Social Snap
×