Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78686
| X-Received | by 10.50.36.101 with SMTP id p5mr2908249igj.1.1412417118479; Sat, 04 Oct 2014 03:05:18 -0700 (PDT) |
|---|---|
| X-Received | by 10.50.13.4 with SMTP id d4mr36183igc.16.1412417118400; Sat, 04 Oct 2014 03:05:18 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!uq10no3746236igb.0!news-out.google.com!bc9ni15653igb.0!nntp.google.com!uq10no3746235igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Sat, 4 Oct 2014 03:05:17 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=115.111.247.34; posting-account=f0ib_QoAAADpg3bD2ZkUb6_ewAmdQ6wF |
| NNTP-Posting-Host | 115.111.247.34 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <54356bfb-b05c-4f18-a855-9276297b0eee@googlegroups.com> (permalink) |
| Subject | pyqt darg and drop |
| From | Sachin Tiwari <sachin.tiwari50@gmail.com> |
| Injection-Date | Sat, 04 Oct 2014 10:05:18 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:78686 |
Show key headers only | View raw
Hi
I want to drag and drop push multiple push buttons but its working for only for last button. And I want to connect them by a wire.
Please help.
import sys
from PyQt4 import QtGui, QtCore
class Button(QtGui.QPushButton):
def mouseMoveEvent(self, e):
if e.buttons() != QtCore.Qt.RightButton:
return
mimeData = QtCore.QMimeData()
mimeData.setText('%d,%d' % (e.x(), e.y()))
pixmap = QtGui.QPixmap.grabWidget(self)
painter = QtGui.QPainter(pixmap)
painter.setCompositionMode(painter.CompositionMode_DestinationIn)
painter.fillRect(pixmap.rect(), QtGui.QColor(0, 0, 0, 127))
painter.end()
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.setPixmap(pixmap)
drag.setHotSpot(e.pos())
if drag.exec_(QtCore.Qt.CopyAction & QtCore.Qt.MoveAction) == QtCore.Qt.MoveAction:
print 'moved'
else:
print 'copied'
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)
button = Button('Button', self)
button1 = Button('Button1', self)
button.move(100, 65)
button1.move(200, 65)
self.buttons = [button]
self.setWindowTitle('Copy or Move')
self.setGeometry(300, 300, 280, 150)
def dragEnterEvent(self, e):
e.accept()
def dropEvent(self, e):
mime = e.mimeData().text()
x, y = map(int, mime.split(','))
if e.keyboardModifiers() & QtCore.Qt.ShiftModifier:
button = Button('Button', self)
button1 = Button('Button1', self)
button.move(e.pos()-QtCore.QPoint(x, y))
button1.move(e.pos()-QtCore.QPoint(x, y))
button.show()
button1.show()
self.buttons.append(button)
self.buttons.append(button1)
e.setDropAction(QtCore.Qt.CopyAction)
else:
e.source().move(e.pos()-QtCore.QPoint(x, y))
e.setDropAction(QtCore.Qt.MoveAction)
e.accept()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Example()
ex.show()
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
pyqt darg and drop Sachin Tiwari <sachin.tiwari50@gmail.com> - 2014-10-04 03:05 -0700 Re: pyqt darg and drop Sachin Tiwari <sachin.tiwari50@gmail.com> - 2014-10-04 03:32 -0700
csiph-web