def __onDragStarted(self, index): # type: (QModelIndex) -> None desc = index.data(QtWidgetRegistry.WIDGET_DESC_ROLE) icon = index.data(Qt.DecorationRole) drag_data = QMimeData() drag_data.setData( "application/vnd.orange-canvas.registry.qualified-name", desc.qualified_name.encode('utf-8')) drag = QDrag(self) drag.setPixmap(icon.pixmap(38)) drag.setMimeData(drag_data) # TODO: Should animate (accept) hide. self.hide() # When a drag is started and the menu hidden the item's tool tip # can still show for a short time UNDER the cursor preventing a # drop. viewport = self.__menu.view().viewport() filter = ToolTipEventFilter() viewport.installEventFilter(filter) drag.exec(Qt.CopyAction) viewport.removeEventFilter(filter)
def startDrag(self, supported_actions): indices = self.selectionModel().selectedIndexes() indices = [i for i in indices if i.flags() & Qt.ItemIsDragEnabled] if indices: data = self.model().mimeData(indices) if not data: return drag = QDrag(self) drag.setMimeData(data) default_action = Qt.IgnoreAction if self.defaultDropAction() != Qt.IgnoreAction and \ supported_actions & self.defaultDropAction(): default_action = self.defaultDropAction() elif (supported_actions & Qt.CopyAction and self.dragDropMode() != self.InternalMove): default_action = Qt.CopyAction res = drag.exec(supported_actions, default_action) if res == Qt.MoveAction: selected = self.selectionModel().selectedIndexes() rows = list(map(QModelIndex.row, selected)) for s1, s2 in reversed(list(slices(rows))): delslice(self.model(), s1, s2) self.dragDropActionDidComplete.emit(res)
def __startDrag(self, button): # type: (QToolButton) -> None """ Start a drag from button """ action = button.defaultAction() desc = action.data() # Widget Description icon = action.icon() drag_data = QMimeData() drag_data.setData( "application/vnd.orange-canvas.registry.qualified-name", desc.qualified_name.encode("utf-8") ) drag = QDrag(button) drag.setPixmap(icon.pixmap(self.iconSize())) drag.setMimeData(drag_data) drag.exec(Qt.CopyAction)
def __startInternalDrag(self, frame, hotSpot=None): drag = QDrag(self) pixmap = QPixmap(frame.size()) frame.render(pixmap) transparent = QPixmap(pixmap.size()) transparent.fill(Qt.transparent) painter = QPainter(transparent) painter.setOpacity(0.35) painter.drawPixmap(0, 0, pixmap.width(), pixmap.height(), pixmap) painter.end() drag.setPixmap(transparent) if hotSpot is not None: drag.setHotSpot(hotSpot) mime = QMimeData() mime.setData("application/x-internal-move", b"") drag.setMimeData(mime) return drag.exec(Qt.MoveAction)