def mousePressEvent( self, event ): # handle an internal move from PyQt4.QtCore import Qt # start a drag event if ( event.button() == Qt.LeftButton and self.dragDropRect().contains( event.pos() ) ): from PyQt4.QtCore import QMimeData from PyQt4.QtGui import QDrag, QPixmap # create the pixmap pixmap = QPixmap.grabWidget( self, self.rect() ) # create the mimedata mimeData = QMimeData() mimeData.setText( 'ItemTitle::%s' % (self.title()) ) # create the drag drag = QDrag(self) drag.setMimeData( mimeData ) drag.setPixmap( pixmap ) drag.setHotSpot( event.pos() ) if ( not drag.exec_() ): self._accordianWidget.emitItemDragFailed(self) event.accept() # determine if the expand/collapse should occur elif ( event.button() == Qt.LeftButton and self.expandCollapseRect().contains( event.pos() ) ): self._clicked = True event.accept() else: event.ignore()
def mousePressEvent(self, event): # handle an internal move # start a drag event if event.button() == Qt.LeftButton and self.dragDropRect().contains( event.pos()): # create the pixmap pixmap = QPixmap.grabWidget(self, self.rect()) # create the mimedata mimeData = QMimeData() mimeData.setText('ItemTitle::%s' % (self.title())) # create the drag drag = QDrag(self) drag.setMimeData(mimeData) drag.setPixmap(pixmap) drag.setHotSpot(event.pos()) if not drag.exec_(): self._accordianWidget.emitItemDragFailed(self) event.accept() # determine if the expand/collapse should occur elif event.button() == Qt.LeftButton and self.expandCollapseRect( ).contains(event.pos()): self._clicked = True event.accept() else: event.ignore()
def mouseMoveEvent(self, event): if event.buttons() != Qt.RightButton: return mimeData = QMimeData() drag = QDrag(self) drag.setMimeData(mimeData) drag.setHotSpot(event.pos() - self.rect().topLeft()) dropAction = drag.start(Qt.MoveAction) if dropAction == Qt.MoveAction: self.close()
def mouseMoveEvent(self,event): #if the left mouse button is used if event.buttons() == Qt.LeftButton: data = QByteArray() mime_data = QMimeData() mime_data.setData(self.mimetext,data) drag = QDrag(self) drag.setMimeData(mime_data) drag.setHotSpot(self.rect().topLeft()) #where do we drag from drop_action = drag.start(Qt.MoveAction) #drag starts
def startDrag(self): image = self.image() data = QMimeData() data.setImageData(image) drag = QDrag(self) drag.setMimeData(data) if max(image.width(), image.height()) > 256: image = image.scaled(QSize(256, 256), Qt.KeepAspectRatio, Qt.SmoothTransformation) pixmap = QPixmap.fromImage(image) drag.setPixmap(pixmap) drag.setHotSpot(pixmap.rect().center()) drag.exec_(Qt.CopyAction)
def mouseMoveEvent(self,event): #if the left mouse button is used if event.buttons() == Qt.LeftButton: data = QByteArray() mime_data = QMimeData() mime_data.setData(self.mimetext,data) drag = QDrag(self) drag.setMimeData(mime_data) drag.setHotSpot(self.rect().topLeft()) #where do we drag from if QT_VERSION_STR < '5': drop_action = drag.start(Qt.MoveAction) #drag starts else: drop_action = drag.exec(Qt.MoveAction) #drag starts
def drag(self, tile=None, meld=None): """returns a drag object""" drag = QDrag(self) mimeData = MimeData(tile, meld) drag.setMimeData(mimeData) tile = tile or meld[0] graphics = tile.graphics tRect = graphics.boundingRect() tRect = self.viewportTransform().mapRect(tRect) pmapSize = QSize(tRect.width() * graphics.scale(), tRect.height() * graphics.scale()) pMap = graphics.pixmapFromSvg(pmapSize) drag.setPixmap(pMap) drag.setHotSpot(QPoint(pMap.width()/2, pMap.height()/2)) return drag
def startDrag(self, mainwin, ev): d = mainwin.currentDocument() if not d: return url = d.url() if url.isEmpty(): return drag = QDrag(mainwin) data = QMimeData() data.setUrls([url]) drag.setMimeData(data) pixmap = mainwin.style().standardPixmap(QStyle.SP_FileIcon, 0, mainwin) hotspot = QPoint(pixmap.width() - 5, 5) drag.setPixmap(pixmap) drag.setHotSpot(hotspot) drag.start(Qt.LinkAction | Qt.CopyAction)
def mouseMoveEvent(self, event): if event.buttons() != Qt.LeftButton: return mimeData = QMimeData() if self.pos == -1: return mimeData.setData("splitter/fragment", QByteArray.number(self.pos)) drag = QDrag(self) drag.setMimeData(mimeData) drag.setHotSpot(event.pos() - self.rect().topLeft()) dropAction = drag.start(Qt.MoveAction) if dropAction == Qt.MoveAction: self.close()
def startDrag(self): image = self.image() data = QMimeData() data.setImageData(image) drag = QDrag(self) drag.setMimeData(data) if max(image.width(), image.height()) > 256: image = image.scaled(QSize(256, 256), Qt.KeepAspectRatio, Qt.SmoothTransformation) p = QPainter() p.begin(image) p.setCompositionMode(QPainter.CompositionMode_DestinationIn) p.fillRect(image.rect(), QColor(0, 0, 0, 160)) p.end() pixmap = QPixmap.fromImage(image) drag.setPixmap(pixmap) drag.setHotSpot(pixmap.rect().center()) drag.exec_(Qt.CopyAction)
def startDrag(self, supportedActions): """ Overwritten function of QTreeWidget. This function creates a QDrag object representing the selected element of this TreeWidget. """ logging.debug(self.__class__.__name__ +": startDrag()") indexes = self.selectedIndexes() if len(indexes) > 0: data = self.model().mimeData(indexes) if not data: return drag = QDrag(self) drag.setMimeData(data) if self.model().data(indexes[0], Qt.DecorationRole).type() == QVariant.Icon: icon = QIcon(self.model().data(indexes[0], Qt.DecorationRole)) drag.setPixmap(icon.pixmap(QSize(50, 50))) drag.setHotSpot(QPoint(drag.pixmap().width()/2, drag.pixmap().height()/2)) # center icon in respect to cursor defaultDropAction = Qt.IgnoreAction drag.exec_(supportedActions, defaultDropAction)
def mouseMoveEvent(self, e): if self.drag_start is None: pass x = e.x() - self.drag_start.x() y = e.y() - self.drag_start.y() dist = QApplication.startDragDistance() if not self.draggable or x > dist or y > dist: return drag = QDrag(self) mime = QMimeData() mime.setText(self.__class__.__name__) mime.part = self drag.setMimeData(mime) pixmap = QPixmap.grabWidget(self) pixmap.setAlphaChannel(pixmap) drag.setPixmap(pixmap) drag.setHotSpot(QPoint(drag.pixmap().width() / 2, drag.pixmap().height())) drag.start(Qt.CopyAction)
def mouseMoveEvent(self, e): if self.drag_start is None: pass x = e.x() - self.drag_start[0] y = e.y() - self.drag_start[1] dist = QApplication.startDragDistance() if (self.draggable is False) or (abs(x) < dist and abs(y) < dist): return drag = QDrag(self) mime = QMimeData() mime.setText(self.__class__.__name__) mime.part = self drag.setMimeData(mime) pixmap = QPixmap.grabWidget(self) pixmap.setAlphaChannel(pixmap) drag.setPixmap(pixmap) drag.setHotSpot(QPoint(drag.pixmap().width() / 2, drag.pixmap().height())) self.dragging = True drag.start(Qt.CopyAction)
def startDrag(self, drop_actions): selected_doc_items = self.selectedItems() data = QByteArray() stream = QDataStream(data, QIODevice.WriteOnly) for doc_item in selected_doc_items: stream.writeQString(doc_item.text() + ":" + doc_item.get_full_name()) mimeData = QMimeData() mimeData.setData("application/x-doc-list", data) drag = QDrag(self) drag.setMimeData(mimeData) drag.setHotSpot(QPoint(0, 0)) if drag.start(Qt.MoveAction) == Qt.MoveAction: docs = [] for doc_item in selected_doc_items: # self.takeItem(self.row(doc_item)) docs.append(doc_item.text()) self.emit(SIGNAL("removeDocs"), docs)
def mouseMoveEvent(self, event): drag = QDrag(event.widget()) data = QMimeData() data.setText(self.commit.name()) drag.setMimeData(data) #data.setColorData(GREEN) pixmap = QPixmap(COMMIT_WIDTH, COMMIT_HEIGHT) pixmap.fill(WHITE) painter = QPainter(pixmap) painter.translate(0, 0) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(self.color)) painter.drawPath(self.setup_display(0, 0)) painter.end() pixmap.setMask(pixmap.createHeuristicMask()) drag.setPixmap(pixmap) drag.setHotSpot(QPoint(0, 0)) drag.start()
def startDrag(self, supportedActions): """ Overwritten function of QTreeWidget. This function creates a QDrag object representing the selected element of this TreeWidget. """ logging.debug(self.__class__.__name__ + ": startDrag()") indexes = self.selectedIndexes() if len(indexes) > 0: data = self.model().mimeData(indexes) if not data: return drag = QDrag(self) drag.setMimeData(data) if self.model().data(indexes[0], Qt.DecorationRole).type() == QVariant.Icon: icon = QIcon(self.model().data(indexes[0], Qt.DecorationRole)) drag.setPixmap(icon.pixmap(QSize(50, 50))) drag.setHotSpot( QPoint(drag.pixmap().width() / 2, drag.pixmap().height() / 2)) # center icon in respect to cursor defaultDropAction = Qt.IgnoreAction drag.exec_(supportedActions, defaultDropAction)
def mouseMoveEvent(self, e): # Chequear que se esté presionando el botón izquierdo if e.buttons() != Qt.LeftButton: return # posicion del click dentro del gmod mimeData = QMimeData() pixmap = QPixmap.grabWidget(self) painter = QPainter(pixmap) painter.setCompositionMode(painter.CompositionMode_DestinationIn) painter.fillRect(pixmap.rect(), QColor(0, 0, 0, 127)) painter.end() drag = QDrag(self) # escribir el MimeData drag.setMimeData(mimeData) # establecer el Pixmap drag.setPixmap(pixmap) # posicionar correctamente el pixmap drag.setHotSpot(e.pos()) drag.exec_(Qt.MoveAction)
def mouseMoveEvent(self, event): if not (event.buttons() and Qt.LeftButton): return currentItem = self.currentItem() if(currentItem.isFile()): if(currentItem.isPic()): currentItemName = self.currentItem().getPath() data = QByteArray() stream = QDataStream(data, QIODevice.WriteOnly) stream.writeQString(currentItemName) icon = Icons.image pixmap = icon.pixmap(64, 64) mimeData = QMimeData() mimeData.setText(currentItemName) mimeData.setData('application/x-item', data) drag = QDrag(self) drag.setPixmap(pixmap) drag.setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2)) drag.setMimeData(mimeData) dropAction = drag.start(Qt.CopyAction)
def startDrag(self, event): child = self.childAt(event.pos()) if not child: return pos_in_child = event.pos() - child.pos() data = QByteArray() stream = QDataStream(data, QIODevice.WriteOnly) stream << QVariant(child.value()) << QPoint(pos_in_child) mime = QMimeData() mime.setData("application/x-fridgemagnet", data) drag = QDrag(child) drag.setMimeData(mime) drag.setPixmap(QPixmap.grabWidget(child)) drag.setHotSpot(pos_in_child) child.hide() if (drag.start(Qt.MoveAction or Qt.CopyAction) == Qt.MoveAction): child.close() else: child.show()