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 copy(self): """Copy to the clipboard""" data = QMimeData() text = '\n'.join([cursor.selectedText() \ for cursor in self.cursors()]) data.setText(text) data.setData(self.MIME_TYPE, text.encode('utf8')) QApplication.clipboard().setMimeData(data)
def mouseMoveEvent(self, mme): if mme.button() == Qt.NoButton and self._drag_start: # for some reason, the left button is being mapped to NoButton drag_distance = mme.pos() - self._drag_start drag_distance = drag_distance.manhattanLength() if drag_distance > QApplication.startDragDistance(): drag = QDrag(self) mime_data = QMimeData() mime_data.setText(self.label_spidername.text()) drag.setMimeData(mime_data) drag.exec_(Qt.CopyAction | Qt.MoveAction) super(SpiderToolButton, self).mouseMoveEvent(mme)
def mouseMoveEvent(self, mme): if mme.button( ) == Qt.NoButton and self._drag_start: # for some reason, the left button is being mapped to NoButton drag_distance = mme.pos() - self._drag_start drag_distance = drag_distance.manhattanLength() if drag_distance > QApplication.startDragDistance(): drag = QDrag(self) mime_data = QMimeData() mime_data.setText(self.label_spidername.text()) drag.setMimeData(mime_data) drag.exec_(Qt.CopyAction | Qt.MoveAction) super(SpiderToolButton, self).mouseMoveEvent(mme)
def _drag_text ( self, text ): mime_data = QMimeData() mime_data.setText( text ) return mime_data
def set_clipboard_html(self): """Place the HTML displayed in the HTML view widget into the system clipboard. """ data = QMimeData() data.setText(self.plain) data.setHtml(self.html) QApplication.clipboard().setMimeData(data)