當前位置: 首頁>>代碼示例>>Python>>正文


Python QDrag.setHotSpot方法代碼示例

本文整理匯總了Python中PyQt5.QtGui.QDrag.setHotSpot方法的典型用法代碼示例。如果您正苦於以下問題:Python QDrag.setHotSpot方法的具體用法?Python QDrag.setHotSpot怎麽用?Python QDrag.setHotSpot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt5.QtGui.QDrag的用法示例。


在下文中一共展示了QDrag.setHotSpot方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mouseMoveEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
    def mouseMoveEvent(self, event):
        if QLineF(QPointF(event.screenPos()), QPointF(event.buttonDownScreenPos(Qt.LeftButton))).length() < QApplication.startDragDistance():
            return

        drag = QDrag(event.widget())
        mime = QMimeData()
        drag.setMimeData(mime)

        ColorItem.n += 1
        if ColorItem.n > 2 and qrand() % 3 == 0:
            image = QImage(':/images/head.png')
            mime.setImageData(image)
            drag.setPixmap(QPixmap.fromImage(image).scaled(30,40))
            drag.setHotSpot(QPoint(15, 30))
        else:
            mime.setColorData(self.color)
            mime.setText("#%02x%02x%02x" % (self.color.red(), self.color.green(), self.color.blue()))

            pixmap = QPixmap(34, 34)
            pixmap.fill(Qt.white)

            painter = QPainter(pixmap)
            painter.translate(15, 15)
            painter.setRenderHint(QPainter.Antialiasing)
            self.paint(painter, None, None)
            painter.end()

            pixmap.setMask(pixmap.createHeuristicMask())

            drag.setPixmap(pixmap)
            drag.setHotSpot(QPoint(15, 20))

        drag.exec_()
        self.setCursor(Qt.OpenHandCursor)
開發者ID:CarlosAndres12,項目名稱:pyqt5,代碼行數:36,代碼來源:dragdroprobot.py

示例2: mousePressEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
    def mousePressEvent(self, event):
        child = self.childAt(event.pos())
        if not child:
            return

        pixmap = QPixmap(child.pixmap())

        itemData = QByteArray()
        dataStream = QDataStream(itemData, QIODevice.WriteOnly)
        dataStream << pixmap << QPoint(event.pos() - child.pos())

        mimeData = QMimeData()
        mimeData.setData('application/x-dnditemdata', itemData)

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - child.pos())

        tempPixmap = QPixmap(pixmap)
        painter = QPainter()
        painter.begin(tempPixmap)
        painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127))
        painter.end()

        child.setPixmap(tempPixmap)

        if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
            child.close()
        else:
            child.show()
            child.setPixmap(pixmap)
開發者ID:Axel-Erfurt,項目名稱:pyqt5,代碼行數:34,代碼來源:draggableicons.py

示例3: mouseMoveEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
    def mouseMoveEvent(self, ev):
        if (ev.pos() - self.press_pos).manhattanLength() > 16:
            # print("drag start")

            drag = QDrag(self.controller._gui._window)

            # Create the drag thumbnail
            if False:
                pix = QPixmap(self.tile_rect.width(), self.tile_rect.height())
                painter = QPainter(pix)
                self.paint(painter, None, None)
                painter.end()
                drag.setPixmap(pix)
                drag.setHotSpot(ev.pos().toPoint() - self.tile_rect.topLeft())
            else:
                pix = QPixmap("/usr/share/icons/mate/32x32/actions/gtk-dnd-multiple.png").scaled(48, 48)
                drag.setPixmap(pix)

            if not self.isSelected():
                self.controller.clear_selection()
                self.setSelected(True)

            mime_data = self.controller.selection_to_mimedata(uri_only=True)
            drag.setMimeData(mime_data)

            # Qt does not allow custom drag actions officially. The
            # default drag action value is however carried through
            # even if it's invalid, but cursor changes and signals
            # like actionChanged() misbehave. The DragWidget class is
            # a workaround.
            drag_widget = DragWidget(None)  # noqa: F841

            # this will eat up the mouseReleaseEvent
            drag.exec(Qt.CopyAction | Qt.MoveAction | Qt.LinkAction | 0x40, 0x40)
開發者ID:Grumbel,項目名稱:dirtool,代碼行數:36,代碼來源:file_item.py

示例4: mouseMoveEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
    def mouseMoveEvent(self, event):
        """ If the mouse moves far enough when the left mouse button is held
            down, start a drag and drop operation.
        """
        if not event.buttons() & Qt.LeftButton:
            return

        if (event.pos() - self.dragStartPosition).manhattanLength() \
             < QApplication.startDragDistance():
            return

        if not self.hasImage:
            return

        drag = QDrag(self)
        mimeData = QMimeData()

        output = QByteArray()
        outputBuffer = QBuffer(output)
        outputBuffer.open(QIODevice.WriteOnly)
        self.imageLabel.pixmap().toImage().save(outputBuffer, 'PNG')
        outputBuffer.close()
        mimeData.setData('image/png', output)

        drag.setMimeData(mimeData)
        drag.setPixmap(self.imageLabel.pixmap().scaled(64, 64, Qt.KeepAspectRatio))
        drag.setHotSpot(QPoint(drag.pixmap().width() / 2,
                                      drag.pixmap().height()))
        drag.start()
開發者ID:death-finger,項目名稱:Scripts,代碼行數:31,代碼來源:separations.py

示例5: mouseMoveEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
 def mouseMoveEvent(self, e):
     if e.buttons() != Qt.RightButton:
         return
     mimeData = QMimeData()
     drag = QDrag(self)
     drag.setMimeData(mimeData)
     drag.setHotSpot(e.pos() - self.rect().topLeft())
     dropAction = drag.exec_(Qt.MoveAction)
開發者ID:HappyJamesL,項目名稱:pyqtlearn,代碼行數:10,代碼來源:dragdrop.py

示例6: newComponentButtonMousePress

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
	def newComponentButtonMousePress(self, componentType, event):
		self.tool = Tool.NewComponent
		self.mouseState = MouseState.Dragging
		self.newComponentType = componentType
		
		newComponentDrag = QDrag(self.view)
		newComponentDrag.setHotSpot(QPoint(self.view.ui.circuitDiagram.blockSideLength / 2, self.view.ui.circuitDiagram.blockSideLength / 2))
		newComponentDrag.setMimeData(QMimeData())
		newComponentDrag.setPixmap(QPixmap(self.view.ui.circuitDiagram.componentTypeToImageName(componentType)).scaled(self.view.ui.circuitDiagram.blockSideLength, self.view.ui.circuitDiagram.blockSideLength))
		newComponentDrag.exec_(Qt.MoveAction)
開發者ID:bandienkhamgalan,項目名稱:flappyeagle,代碼行數:12,代碼來源:MainController.py

示例7: mouseMoveEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
 def mouseMoveEvent(self, event):
     # if the left mouse button is used
     if self.drag_started:
         data = QByteArray()
         mime_data = QMimeData()
         mime_data.setData(self.mimetext, data)
         drag = QDrag(self) 
         drag.setMimeData(mime_data)
         drag.setPixmap(self.icon.get_icon())
         drag.setHotSpot(self.rect().topLeft())  # where do we drag from
         if drag.exec_(Qt.MoveAction):
             self.parent().icons.remove(self)
             self.deleteLater()
開發者ID:ReneVolution,項目名稱:filer,代碼行數:15,代碼來源:IconWidget.py

示例8: mouseMoveEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
    def mouseMoveEvent(self, e):

        # 右ボタンのときのみDnD有効
        if e.buttons() != Qt.RightButton:
            return

        # MIMEベースでDnD情報を転送する
        mimeData = QMimeData()

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(e.pos() - self.rect().topLeft())

        # PyQt4ではdrag.start()だった
        dropAction = drag.exec_(Qt.MoveAction)
開發者ID:minus9d,項目名稱:python_exercise,代碼行數:17,代碼來源:ch08-02-dnd-button-widget.py

示例9: startDrag

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
 def startDrag(self, mainwin, ev):
     d = mainwin.currentDocument()
     if not d:
         return
     url = d.url()
     if url.isEmpty():
         return
     drag = QDrag(mainwin)
     data = QMimeData()
     data.setUrls([url])
     drag.setMimeData(data)
     pixmap = mainwin.style().standardPixmap(QStyle.SP_FileIcon, 0, mainwin)
     hotspot = QPoint(pixmap.width() - 5, 5)
     drag.setPixmap(pixmap)
     drag.setHotSpot(hotspot)
     drag.start(Qt.LinkAction | Qt.CopyAction)
開發者ID:19joho66,項目名稱:frescobaldi,代碼行數:18,代碼來源:icon_drag_eventhandler.py

示例10: startDrag

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
 def startDrag(self):
     image = self.image()
     data = QMimeData()
     data.setImageData(image)
     drag = QDrag(self)
     drag.setMimeData(data)
     if max(image.width(), image.height()) > 256:
         image = image.scaled(QSize(256, 256), Qt.KeepAspectRatio, Qt.SmoothTransformation)
     p = QPainter()
     p.begin(image)
     p.setCompositionMode(QPainter.CompositionMode_DestinationIn)
     p.fillRect(image.rect(), QColor(0, 0, 0, 160))
     p.end()
     pixmap = QPixmap.fromImage(image)
     drag.setPixmap(pixmap)
     drag.setHotSpot(pixmap.rect().center())
     drag.exec_(Qt.CopyAction)
開發者ID:19joho66,項目名稱:frescobaldi,代碼行數:19,代碼來源:imageviewer.py

示例11: mouseMoveEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
    def mouseMoveEvent(self, e):
        if e.buttons() != Qt.RightButton:
            return

        globalPos = self.mapToGlobal(e.pos())
        tabBar = self.tabBar()
        posInTab = tabBar.mapFromGlobal(globalPos)
        self.indexTab = tabBar.tabAt(e.pos())
        tabRect = tabBar.tabRect(self.indexTab)

        pixmap = QPixmap(tabRect.size())
        tabBar.render(pixmap, QPoint(), QRegion(tabRect))
        mimeData = QMimeData()
        drag = QDrag(tabBar)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        cursor = QCursor(Qt.OpenHandCursor)
        drag.setHotSpot(e.pos() - posInTab)
        drag.setDragCursor(cursor.pixmap(), Qt.MoveAction)
        drag.exec_(Qt.MoveAction)
開發者ID:CJ-Wright,項目名稱:bluesky-browser,代碼行數:22,代碼來源:utils.py

示例12: mousePressEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
    def mousePressEvent(self, event):
        itemData = QByteArray()
        dataStream = QDataStream(itemData, QIODevice.WriteOnly)
        dataStream << QByteArray(self.labelText) << QPoint(event.pos() - self.rect().topLeft())

        mimeData = QMimeData()
        mimeData.setData("application/x-fridgemagnet", itemData)
        mimeData.setText(self.labelText)

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(event.pos() - self.rect().topLeft())
        drag.setPixmap(self.pixmap())

        self.hide()

        if drag.exec_(Qt.MoveAction | Qt.CopyAction, Qt.CopyAction) == Qt.MoveAction:
            self.close()
        else:
            self.show()
開發者ID:Magdno1,項目名稱:Arianrhod,代碼行數:22,代碼來源:fridgemagnets.py

示例13: startDrag

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
    def startDrag(self, supportedActions):
        item = self.currentItem()

        itemData = QByteArray()
        dataStream = QDataStream(itemData, QIODevice.WriteOnly)
        pixmap = QPixmap(item.data(Qt.UserRole))
        location = item.data(Qt.UserRole+1)

        dataStream << pixmap << location

        mimeData = QMimeData()
        mimeData.setData('image/x-puzzle-piece', itemData)

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2))
        drag.setPixmap(pixmap)

        if drag.exec_(Qt.MoveAction) == Qt.MoveAction:
            if self.currentItem() is not None:
                self.takeItem(self.row(item))
開發者ID:death-finger,項目名稱:Scripts,代碼行數:23,代碼來源:puzzle.py

示例14: mousePressEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
    def mousePressEvent(self, event):
        hotSpot = event.pos()

        mimeData = QMimeData()
        mimeData.setText(self.text())
        mimeData.setData('application/x-hotspot',
                '%d %d' % (hotSpot.x(), hotSpot.y()))

        pixmap = QPixmap(self.size())
        self.render(pixmap)

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(hotSpot)

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

        if dropAction == Qt.MoveAction:
            self.close()
            self.update()
開發者ID:PWilsonUofC,項目名稱:VGenes,代碼行數:23,代碼來源:draggabletext.py

示例15: mouseMoveEvent

# 需要導入模塊: from PyQt5.QtGui import QDrag [as 別名]
# 或者: from PyQt5.QtGui.QDrag import setHotSpot [as 別名]
 def mouseMoveEvent(self, event):
     if self.parent() is not self.parent().src_dragwidget:
         for item in self.parent().src_selected:
             item.icon.deselect_icon()
         self.parent().clear_dnd()
     # if self.drag_started:
     data = QByteArray()
     mime_data = QMimeData()
     mime_data.setData(self.mimetext, data)
     drag = QDrag(self) 
     drag.setMimeData(mime_data)
     drag.setPixmap(self.icon.get_icon())
     drag.setHotSpot(self.rect().topLeft())
     if drag.exec_(Qt.MoveAction):
         if len(self.parent().src_selected) > 0:
             for item in self.parent().src_selected:
                 self.parent().icons.remove(item)
                 item.deleteLater()
         else:
             self.parent().icons.remove(self)
             self.deleteLater()
     self.parent().clear_dnd()
開發者ID:freeaks,項目名稱:filer,代碼行數:24,代碼來源:iconwidget.py


注:本文中的PyQt5.QtGui.QDrag.setHotSpot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。