Ejemplo n.º 1
0
 def hCopy(self):
     """
     # slot for action copy_to_clipboard
     """
     sel = self.listWdg.selectedItems()
     ####################
     # test code
     l = []
     for item in sel:
         # get url from path
         l.append(QUrl.fromLocalFile(item.data(Qt.UserRole)[0]))
     # init clipboard data
     q = QMimeData()
     # set some Windows magic values for copying files from system clipboard : Don't modify
     # 1 : copy; 2 : move
     q.setData("Preferred DropEffect", QByteArray(1, "2"))
     q.setUrls(l)
     # end of test code
     #####################
     # copy image to clipboard
     item = sel[0]
     filename = item.data(Qt.UserRole)[0]
     if filename.endswith(IMAGE_FILE_EXTENSIONS):
         q.setImageData(QImage(sel[0].data(Qt.UserRole)[0]))
     QApplication.clipboard().clear()
     QApplication.clipboard().setMimeData(q)
Ejemplo n.º 2
0
 def mouseMoveEvent(self, event):
     """Start dragging action if needed."""
     if not event.buttons() & Qt.LeftButton:
         return
     if not self.drag_start_pos:
         return
     if not self.drag_indexes:
         return
     if (event.pos() - self.drag_start_pos
         ).manhattanLength() < QApplication.startDragDistance():
         return
     drag = QDrag(self)
     mimeData = QMimeData()
     urls = list()
     for index in self.drag_indexes:
         file_path = index.data(Qt.UserRole)
         urls.append(QUrl.fromLocalFile(file_path))
     mimeData.setUrls(urls)
     drag.setMimeData(mimeData)
     icon = self.drag_indexes[0].data(Qt.DecorationRole)
     if icon:
         pixmap = icon.pixmap(32, 32)
         drag.setPixmap(pixmap)
         drag.setHotSpot(pixmap.rect().center())
     drag.exec_()
Ejemplo n.º 3
0
    def mouseMoveEvent(self, event):
        """start Drag and prepare for Drop.

        :type event: QMoveEvent
        マウスを動かした嶺がQApplication.startDragDistance()を超えると、Drag開始されたと認識し、
        そのための準備を行う。QMimeDataを使って、データをやりとりする。
        """
        if not (event.buttons() & Qt.LeftButton):
            return
        if (event.pos() - self.dragStartPosition).manhattanLength() \
                < QApplication.startDragDistance():
            return

        if self.isDragging:
            indexes = self.selectedIndexes()
            urls = self.url_list(indexes)

            mimeData = QMimeData()
            # mimeData.setData(self.mime_URLS, convert_to_bytearray(urls))
            mimeData.setUrls(urls)

            file_icon = self.style().standardIcon(QStyle.SP_FileIcon)
            pixmap = file_icon.pixmap(32, 32)

            drag = QDrag(self)
            drag.setMimeData(mimeData)
            drag.setPixmap(pixmap)
            drag.setHotSpot(QPoint(0, 0))

            dropAction = drag.exec_(Qt.CopyAction | Qt.MoveAction,
                                    Qt.CopyAction)
            if dropAction == Qt.MoveAction:
                pass

        else:
            self.rubberBand.setGeometry(
                QRect(self.dragStartPosition, event.pos()).normalized())
            super(PlaylistView, self).mouseMoveEvent(event)