Esempio n. 1
0
 def mouseMoveEvent(self, event):
     if not self.image_list.drag_icon:
         return
     if qt_version_info >= (6, 0):
         pos = event.position()
     else:
         pos = event.pos()
     if ((pos - self.drag_start_pos).manhattanLength() <
             QtWidgets.QApplication.startDragDistance()):
         return
     if not self.get_selected():
         # user has started dragging an unselected image
         self.image_list.select_image(self)
     paths = []
     for image in self.image_list.get_selected_images():
         paths.append(image.path)
     if not paths:
         return
     drag = QtGui.QDrag(self)
     # construct icon
     count = min(len(paths), 8)
     src_icon = self.image_list.drag_icon
     src_w = src_icon.width()
     src_h = src_icon.height()
     margin = (count - 1) * 4
     if count == 1:
         icon = src_icon
     else:
         icon = QtGui.QPixmap(src_w + margin, src_h + margin)
         icon.fill(Qt.transparent)
         try:
             paint = QtGui.QPainter(icon)
             for i in range(count):
                 paint.drawPixmap(QtCore.QPoint(margin - (i * 4), i * 4),
                                  src_icon)
         finally:
             del paint
     drag.setPixmap(icon)
     if self.image_list.drag_hotspot:
         x, y = self.image_list.drag_hotspot
     else:
         x, y = src_w // 2, src_h
     drag.setHotSpot(QtCore.QPoint(x, y + margin))
     mimeData = QtCore.QMimeData()
     mimeData.setData(DRAG_MIMETYPE, repr(paths).encode('utf-8'))
     drag.setMimeData(mimeData)
     if qt_version_info >= (6, 0):
         drag.exec(Qt.CopyAction)
     else:
         drag.exec_(Qt.CopyAction)
Esempio n. 2
0
 def mouseMoveEvent(self, event):
     if not self.image_list.drag_icon:
         return
     if ((event.pos() - self.drag_start_pos).manhattanLength() <
                                 QtWidgets.QApplication.startDragDistance()):
         return
     paths = []
     for image in self.image_list.get_selected_images():
         paths.append(image.path)
     if not paths:
         return
     drag = QtGui.QDrag(self)
     # construct icon
     count = min(len(paths), 8)
     src_icon = self.image_list.drag_icon
     src_w = src_icon.width()
     src_h = src_icon.height()
     margin = (count - 1) * 4
     if count == 1:
         icon = src_icon
     else:
         icon = QtGui.QPixmap(src_w + margin, src_h + margin)
         icon.fill(Qt.transparent)
         with QtGui.QPainter(icon) as paint:
             for i in range(count):
                 paint.drawPixmap(
                     QtCore.QPoint(margin - (i * 4), i * 4), src_icon)
     drag.setPixmap(icon)
     if src_h == src_w:
         # round marker used in Bing maps version 8
         drag.setHotSpot(QtCore.QPoint(src_w // 2, (src_h // 2) + margin))
     else:
         drag.setHotSpot(QtCore.QPoint(src_w // 2, src_h + margin))
     mimeData = QtCore.QMimeData()
     mimeData.setData(DRAG_MIMETYPE, repr(paths).encode('utf-8'))
     drag.setMimeData(mimeData)
     dropAction = drag.exec_(Qt.CopyAction)