本文整理匯總了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)