def dropEvent(self, event: QDropEvent): if not self.scene_definition_windows.scene_size_initialized: QMessageBox.warning(None, "Error", "Scene size is not initialized!") event.ignore() return if event.mimeData().hasFormat(PhysicalObjectsModel.MIME_TYPE): dropped_po = pickle.loads(event.mimeData().data( PhysicalObjectsModel.MIME_TYPE)) if dropped_po: self.dropped_physical_object = dropped_po self.__physical_objects_model.add_physical_object_to_scene( dropped_po) dropped_po.scene_position = \ sceneutil.mouse_coordinates_to_image_coordinates(event.pos().x(), event.pos().y(), self.camera_view_size, self.image_frame) event.setDropAction(Qt.CopyAction) event.accept() else: event.ignore() else: event.ignore()
def dropEvent(self, e: QDropEvent): # 마우스 위치를 이용하여 버튼의 위치를 변경 position = e.pos() self.btn.move(position) e.setDropAction(Qt.MoveAction) e.accept()
def onDrop(self, event: QDropEvent): if DEBUG: print('CalcSubWnd : onDrop') print(event.mimeData().text()) if event.mimeData().hasFormat(LISTBOX_MIMETYPE): eventData = event.mimeData().data(LISTBOX_MIMETYPE) dataStream = QDataStream(eventData, QIODevice.ReadOnly) pixmap = QPixmap() dataStream >> pixmap op_code = dataStream.readQString() text = dataStream.readQString() mouse_pos = event.pos() scene_pos = self.scene.grScene.views()[0].mapToScene(mouse_pos) if DEBUG: print(f'DROP: {op_code} {text} at {scene_pos}') try: node = NodeFactory.from_op_code(op_code)(self.scene) node.setPos(scene_pos.x(), scene_pos.y()) self.scene.history.storeHistory('Create node {}'.format( node.__class__.__name__)) event.setDropAction(Qt.MoveAction) event.accept() except Exception as e: dumpException(e) else: if DEBUG: print(' ... drop ignored, not requested format ', LISTBOX_MIMETYPE) event.ignore()
def dropEvent(self, event: QDropEvent) -> None: if event.mimeData().hasUrls: event.setDropAction(Qt.CopyAction) event.accept() for url in event.mimeData().urls(): item = ResourcesItem() extension = os.path.splitext(url.fileName())[1] if extension == ".png" or extension == ".jpg" or extension == ".jpeg" or extension == ".bmp": item.setWhatsThis("Image") item.setIcon(QIcon(url.toLocalFile())) item.mySetData(QPixmap(url.toLocalFile())) elif extension == ".ttf": item.setWhatsThis("Font") item.setIcon(QIcon("Images/FontIcon.png")) fontId = QFontDatabase().addApplicationFont(url.toLocalFile()) item.mySetData(str(fontId)) else: return item.setText(os.path.splitext(url.fileName())[0]) item.mySetUrl(url.toLocalFile()) self.addItem(item) else: event.ignore()
def dropEvent(self, e: QDropEvent): """Handle Drag and Drop events. The :py:class:`QDropEvent` performs the actual drop operation. We support the following operations: if an Image is dropped, we will use it as input image for the :py:class:`Toolbox`. """ mimeData = e.mimeData() if mimeData.hasUrls() and self._toolbox: # 1. We just consider the first URL, even if multiple URLs # are provided. url = mimeData.urls()[0] LOG.info("Drag and dropped %d URLs, took first: %s", len(mimeData.urls()), url) # 2. Convert the URL to a local filename filename = url.toLocalFile() description = f"Dropped in image ({filename})" LOG.info("Converted URL to local filename: '%s'", filename) # 3. Set this file as input image for the toolbox. self._toolbox.set_input_from_file(filename, description=description) # 4. Mark the Drop action as accepted (we actually perform # a CopyAction, no matter what was proposed) if e.proposedAction() == Qt.CopyAction: e.acceptProposedAction() else: # If you set a drop action that is not one of the # possible actions, the drag and drop operation will # default to a copy operation. e.setDropAction(Qt.CopyAction) e.accept()
def dropEvent(self, event: QDropEvent): if event.mimeData().hasUrls: event.setDropAction(Qt.CopyAction) event.accept() self.drop.emit(event.mimeData().urls()) else: event.ignore()
def dropEvent(self, event: QtGui.QDropEvent) -> None: """ An Item has been moved inside our HierarchyWidget, Move it to the correct location on the server. """ try: draggedItem = self.selectedItems()[0] except: return targetItem = self.itemAt(event.pos()) event.setDropAction(QtCore.Qt.MoveAction) # event.accept() super(HierarchyTreeWidget, self).dropEvent(event) if not targetItem: # Moved to the end of the list if self.topLevelItemCount() > 1: newSortIndex = self.topLevelItem(self.topLevelItemCount() - 2).entryData["sortindex"] + 1 else: newSortIndex = None self.reparent(draggedItem.entryData["key"], self.rootNode, sortIndex=newSortIndex) else: if draggedItem.parent() is targetItem: # Moved to subitem self.reparent(draggedItem.entryData["key"], targetItem.entryData["key"]) else: # Moved within its parent list while targetItem: childIndex = 0 while childIndex < targetItem.childCount(): currChild = targetItem.child(childIndex) if currChild is draggedItem: if childIndex == 0 and targetItem.childCount() > 1: # is now 1st item newSortIndex = targetItem.child(1).entryData["sortindex"] - 1 elif childIndex == (targetItem.childCount() - 1) and childIndex > 0: # is now lastitem newSortIndex = targetItem.child(childIndex - 1).entryData["sortindex"] + 1 elif childIndex > 0 and childIndex < (targetItem.childCount() - 1): # in between newSortIndex = (targetItem.child(childIndex - 1).entryData["sortindex"] + targetItem.child(childIndex + 1).entryData["sortindex"]) / 2.0 else: # We are the only one in this layer newSortIndex = None self.reparent(draggedItem.entryData["key"], targetItem.entryData["key"], newSortIndex) return childIndex += 1 targetItem = targetItem.parent() childIndex = 0 currChild = self.topLevelItem(childIndex) while currChild: if currChild is draggedItem: if childIndex == 0 and self.topLevelItemCount() > 1: # is now 1st item newSortIndex = self.topLevelItem(1).entryData["sortindex"] - 1 elif childIndex == (self.topLevelItemCount() - 1) and childIndex > 0: # is now lastitem newSortIndex = self.topLevelItem(childIndex - 1).entryData["sortindex"] + 1 elif childIndex > 0 and childIndex < (self.topLevelItemCount() - 1): # in between newSortIndex = (self.topLevelItem(childIndex - 1).entryData["sortindex"] + self.topLevelItem(childIndex + 1).entryData["sortindex"]) / 2.0 else: # We are the only one in this layer newSortIndex = None self.reparent(draggedItem.entryData["key"], self.rootNode, newSortIndex) return childIndex += 1 currChild = self.topLevelItem(childIndex)
def drag_handler(self, event: QDropEvent, drop: bool=False): if event.mimeData().hasUrls(): event.setDropAction(Qt.CopyAction) event.accept() if drop: self.files_dropped.emit([url.toLocalFile() for url in event.mimeData().urls()]) else: event.ignore()
def dropEvent(self, a0: QtGui.QDropEvent) -> None: if a0.mimeData().hasUrls() and len( a0.mimeData().urls()) == 1 and os.path.isfile( a0.mimeData().urls()[0].toLocalFile()): a0.setDropAction(QtCore.Qt.CopyAction) a0.accept() self.file_signal.emit(a0.mimeData().urls()[0].toLocalFile()) else: a0.ignore()
def dropEvent(self, e: QDropEvent): position = e.pos() # 보내온 데이터를 받기 # 그랩 당시의 마우스 위치값을 함께 계산하여 위젯 위치 보정 offset = e.mimeData().data("application/hotspot") x, y = offset.data().decode('utf-8').split() self.btn.move(position - QPoint(int(x), int(y))) e.setDropAction(Qt.MoveAction) e.accept()
def dropEvent(self, event: QDropEvent): if event.mimeData().hasUrls: event.setDropAction(Qt.CopyAction) event.accept() if Args().test: dialog = ExcelLoadingWidget(files=event.mimeData().urls()) dialog.show() else: event.ignore()
def dropEvent(self, event: QDropEvent): if event.mimeData().hasFormat('application/hotspot'): position = event.pos() offset = event.mimeData().data('application/hotspot') x, y = offset.data().decode('utf-8').split() self.btn.move(position - QPoint(int(x), int(y))) event.setDropAction(Qt.MoveAction) event.accept() else: event.ignore()
def dropEvent(self, event: QtGui.QDropEvent) -> None: if event.mimeData().hasUrls: event.setDropAction(Qt.CopyAction) event.accept() for url in event.mimeData().urls(): # print(url.toLocalFile()) self.dropped.emit(url.toLocalFile()) listItem = QListWidgetItem() fname = os.path.basename(url.toLocalFile()) listItem.setText(fname) listItem.setIcon( QtGui.QIcon( os.path.abspath('view/icon/document-list.png'))) self.addItem(listItem) else: event.ignore()
def dropEvent(self, a0: QDropEvent) -> None: if a0.source() == self or self.indexTabToDrag < 0 or not isinstance( a0.source(), TabBar): a0.accept() return a0.setDropAction(Qt.MoveAction) a0.accept() insertAfter = self.tabAt(a0.pos()) try: tab = a0.source().parentWidget().widget(self.indexTabToDrag) packItem = QModelIndex(tab.packItem) index = self.parentWidget().openItemInNewTab(packItem) a0.source().tabCloseRequested.emit(self.indexTabToDrag) except AttributeError as e: print("Error occured while drop Event:", e) else: if insertAfter and insertAfter >= 0: self.moveTab(index, insertAfter + 1) TabBar.indexTabToDrag = -1
def dropEvent(self, event: QtGui.QDropEvent) -> None: """Handles the drop event and loads the image_name into the label. Parameters ---------- event: QDropEvent The identified event """ if event.mimeData().hasImage: event.setDropAction(Qt.CopyAction) self.image = event.mimeData().urls()[0].toLocalFile() x = self.width() y = self.height() im = QPixmap(self.image).scaled( x, y) # , aspectRatioMode=Qt.KeepAspectRatio) im.save(os.getcwd() + "/tmp.jpg") self.image = (os.getcwd() + "/tmp.jpg") self.setPixmap(im) # self.setPixmap(QPixmap(self.image)) self.setStyleSheet("") event.accept() else: event.ignore()
def dropEvent(self, e: QDropEvent) -> None: e.setDropAction(Qt.MoveAction) e.accept()
def dropEvent(self, event: QDropEvent): position = event.pos() self.btn.move(position) event.setDropAction(Qt.MoveAction) event.accept()
def dropEvent(self, e: QtGui.QDropEvent): position = e.pos() self.button.move(position) e.setDropAction(Qt.MoveAction) e.accept()
def dropEvent(self, a0: QtGui.QDropEvent): position = a0.pos() self.button1.move(position) a0.setDropAction(Qt.MoveAction) a0.accept()