Home > other >  [PyQt5] excuse me, how can the drag image, when A drop point A copy, drag point A is still not movin
[PyQt5] excuse me, how can the drag image, when A drop point A copy, drag point A is still not movin

Time:10-23

1. The picture on the QLabel present
2. Only realized drag& The drop of the code is as follows:

 
The from PyQt5. QtWidgets import *
The from PyQt5. QtCore import *
The from PyQt5. QtGui import *
The import sys


The class label (QLabel) :

Def __init__ (self, the title, the parent) :
Super () __init__ (title, parent)

Def mouseMoveEvent (self, e) :

MimeData=(https://bbs.csdn.net/topics/QMimeData)
Drag=QDrag (self)
Drag the setMimeData (mimeData)
Drag. SetHotSpot (e.p OS () - self. The rect (). The topLeft ())
DropAction=drag. Exec_ (Qt. MoveAction)


The class Example (QWidget) :

Def __init__ (self) :
Super () __init__ ()
The self. The initUI ()


Def initUI (self) :
Self. SetAcceptDrops (True)
The self. The button=label (' button ', the self)
Self. Im1=QPixmap (' Scripts/p.i co ')
Self. Button. SetPixmap (self im1)
Self. Button. Move (100, 65)
Self. Button2=label (button2, self)
Self. Button2. Move (200, 65)
Self. SetWindowTitle (' Click or Move)
Self. SetGeometry (300, 300, 280, 150)


Def dragEnterEvent (self, e) :
E.a ccept ()

Def dropEvent (self, e) :
BTN=e.s ource ()
The position=e.p OS ()
BTN. Move (position)
E.s etDropAction (Qt. CopyAction)
E.a ccept ()

If __name__=="__main__ ':
App=QApplication (sys. Argv)
The ex=Example ()
Ex. ShowMaximized ()
App. Exec_ ()
  • Related