本文整理汇总了Python中PyQt4.QtGui.QDrag.pixmap方法的典型用法代码示例。如果您正苦于以下问题:Python QDrag.pixmap方法的具体用法?Python QDrag.pixmap怎么用?Python QDrag.pixmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QDrag
的用法示例。
在下文中一共展示了QDrag.pixmap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startDrag
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import pixmap [as 别名]
def startDrag(self, supportedActions):
""" Overwritten function of QTreeWidget.
This function creates a QDrag object representing the selected element of this TreeWidget.
"""
logging.debug(self.__class__.__name__ +": startDrag()")
indexes = self.selectedIndexes()
if len(indexes) > 0:
data = self.model().mimeData(indexes)
if not data:
return
drag = QDrag(self)
drag.setMimeData(data)
if self.model().data(indexes[0], Qt.DecorationRole).type() == QVariant.Icon:
icon = QIcon(self.model().data(indexes[0], Qt.DecorationRole))
drag.setPixmap(icon.pixmap(QSize(50, 50)))
drag.setHotSpot(QPoint(drag.pixmap().width()/2, drag.pixmap().height()/2)) # center icon in respect to cursor
defaultDropAction = Qt.IgnoreAction
drag.exec_(supportedActions, defaultDropAction)
示例2: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import pixmap [as 别名]
def mouseMoveEvent(self, e):
if self.drag_start is None:
pass
x = e.x() - self.drag_start.x()
y = e.y() - self.drag_start.y()
dist = QApplication.startDragDistance()
if not self.draggable or x > dist or y > dist:
return
drag = QDrag(self)
mime = QMimeData()
mime.setText(self.__class__.__name__)
mime.part = self
drag.setMimeData(mime)
pixmap = QPixmap.grabWidget(self)
pixmap.setAlphaChannel(pixmap)
drag.setPixmap(pixmap)
drag.setHotSpot(QPoint(drag.pixmap().width() / 2,
drag.pixmap().height()))
drag.start(Qt.CopyAction)
示例3: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import pixmap [as 别名]
def mouseMoveEvent(self, e):
if self.drag_start is None:
pass
x = e.x() - self.drag_start[0]
y = e.y() - self.drag_start[1]
dist = QApplication.startDragDistance()
if (self.draggable is False) or (abs(x) < dist and abs(y) < dist):
return
drag = QDrag(self)
mime = QMimeData()
mime.setText(self.__class__.__name__)
mime.part = self
drag.setMimeData(mime)
pixmap = QPixmap.grabWidget(self)
pixmap.setAlphaChannel(pixmap)
drag.setPixmap(pixmap)
drag.setHotSpot(QPoint(drag.pixmap().width() / 2,
drag.pixmap().height()))
self.dragging = True
drag.start(Qt.CopyAction)