Reputation: 23
When I drag my QPushButton, it disappears until dropped. I want to show the button all the time while it is being dragged. How to do that?
Downwards my Button that is being dragged around including the QDrag object.
Happy to share more code if needed :)
A photo of my screen
class DraggableCodeBlock(QPushButton):
def __init__(self, width, height, offset_left, offset_top, parent, command):
super().__init__(parent=parent)
self.parent = parent
self.setText(command)
self.show()
def mouseMoveEvent(self, e):
if e.buttons() != Qt.LeftButton:
return
mimeData = QMimeData()
drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(e.pos() - self.rect().topLeft())
dropAction = drag.exec_(Qt.MoveAction)
super(DraggableCodeBlock, self).mouseMoveEvent(e)
def mousePressEvent(self, e):
super().mousePressEvent(e)
if e.button() == Qt.LeftButton or not(self.is_mobile):
print('press')
Upvotes: 2
Views: 274
Reputation: 244282
you must set the image you want to show through setPixmap()
, to get the image of the widget you should use grab()
:
drag = QDrag(self)
drag.setPixmap(self.grab())
Upvotes: 1