Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import sys
- from PySide import QtGui, QtCore
- class Button(QtGui.QPushButton):
- def __init__(self, title, parent):
- super(Button, self).__init__(title, parent)
- def mouseMoveEvent(self, e):
- if e.buttons() == QtCore.Qt.LeftButton:
- self.setDown(False)
- mimeData = QtCore.QMimeData()
- drag = QtGui.QDrag(self)
- drag.setMimeData(mimeData)
- drag.setHotSpot(e.pos() - self.rect().topLeft())
- drag.start(QtCore.Qt.MoveAction)
- def mousePressEvent(self, e):
- QtGui.QPushButton.mousePressEvent(self, e)
- if e.button() == QtCore.Qt.LeftButton:
- print 'press'
- class Example(QtGui.QWidget):
- def __init__(self):
- super(Example, self).__init__()
- self.initUI()
- def initUI(self):
- self.setAcceptDrops(True)
- self.btn = Button('Button', self)
- self.btn.move(100, 65)
- self.setGeometry(300, 300, 300, 150)
- self.setWindowTitle('Click or move')
- self.show()
- def dragEnterEvent(self, e):
- e.accept()
- def dropEvent(self, e):
- position = e.pos()
- newButton = Button(self.btn.text(), self)
- newButton.show()
- newButton.move(position)
- e.setDropAction(QtCore.Qt.MoveAction)
- e.accept()
- print 'Original button is down:', self.btn.isDown()
- print 'New button is down:', newButton.isDown()
- def main():
- app = QtGui.QApplication(sys.argv)
- ex = Example()
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement