本文整理汇总了Python中PyQt5.QtGui.QDrag.setPixmap方法的典型用法代码示例。如果您正苦于以下问题:Python QDrag.setPixmap方法的具体用法?Python QDrag.setPixmap怎么用?Python QDrag.setPixmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QDrag
的用法示例。
在下文中一共展示了QDrag.setPixmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouseMoveEvent
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [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)
示例2: mouseMoveEvent
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [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)
示例3: mousePressEvent
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [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)
示例4: mouseMoveEvent
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [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()
示例5: startDrag
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [as 别名]
def startDrag(self):
self.mimeData = MimeData()
self.mimeData.dataRequested.connect(self.createData, Qt.DirectConnection)
drag = QDrag(self)
drag.setMimeData(self.mimeData)
drag.setPixmap(QPixmap(':/images/drag.png'))
drag.exec_(Qt.CopyAction)
示例6: __dragSnapshot
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [as 别名]
def __dragSnapshot(self):
"""
Private slot handling the dragging of the preview picture.
"""
drag = QDrag(self)
mimeData = QMimeData()
mimeData.setImageData(self.__snapshot)
drag.setMimeData(mimeData)
drag.setPixmap(self.preview.pixmap())
drag.exec_(Qt.CopyAction)
示例7: dragFile
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [as 别名]
def dragFile(widget, filename, icon=None, dropactions=Qt.CopyAction):
"""Starts dragging the given local file from the widget."""
if icon is None or icon.isNull():
icon = QFileIconProvider().icon(QFileInfo(filename))
drag = QDrag(widget)
data = QMimeData()
data.setUrls([QUrl.fromLocalFile(filename)])
drag.setMimeData(data)
drag.setPixmap(icon.pixmap(32))
drag.exec_(dropactions)
示例8: newComponentButtonMousePress
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [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)
示例9: mouseMoveEvent
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [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()
示例10: mousePressEvent
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [as 别名]
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.drag_started.emit(self.mapToParent(event.pos()))
drag = QDrag(self)
mimeData = QMimeData()
mimeData.setText("Move Signal")
pixmap = QPixmap(self.rect().size())
self.render(pixmap, QPoint(), QRegion(self.rect()))
drag.setPixmap(pixmap)
drag.setMimeData(mimeData)
drag.exec_()
示例11: mouseMoveEvent
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [as 别名]
def mouseMoveEvent(self, evt):
"""
Protected method to handle mouse move events.
@param evt reference to the event (QMouseEvent)
"""
if self.__model is None:
super(E5ModelMenu, self).mouseMoveEvent(evt)
return
if not (evt.buttons() & Qt.LeftButton):
super(E5ModelMenu, self).mouseMoveEvent(evt)
return
manhattanLength = (evt.pos() -
self.__dragStartPosition).manhattanLength()
if manhattanLength <= QApplication.startDragDistance():
super(E5ModelMenu, self).mouseMoveEvent(evt)
return
act = self.actionAt(self.__dragStartPosition)
if act is None:
super(E5ModelMenu, self).mouseMoveEvent(evt)
return
idx = self.index(act)
if not idx.isValid():
super(E5ModelMenu, self).mouseMoveEvent(evt)
return
drag = QDrag(self)
drag.setMimeData(self.__model.mimeData([idx]))
actionRect = self.actionGeometry(act)
if qVersion() >= "5.0.0":
drag.setPixmap(self.grab(actionRect))
else:
drag.setPixmap(QPixmap.grabWidget(self, actionRect))
if drag.exec_() == Qt.MoveAction:
row = idx.row()
if self.__dropIndex == idx.parent() and self.__dropRow <= row:
row += 1
self.__model.removeRow(row, self.__root)
if not self.isAncestorOf(drag.target()):
self.close()
else:
self.aboutToShow.emit()
示例12: startDrag
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [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)
示例13: startDrag
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [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)
示例14: mouseMoveEvent
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [as 别名]
def mouseMoveEvent(self, event):
if (event.buttons() == Qt.LeftButton and
(event.modifiers() == Qt.ControlModifier or
event.modifiers() == Qt.ShiftModifier)):
mime_data = QMimeData()
mime_data.setText(PageWidget.DRAG_MAGIC)
drag = QDrag(self)
drag.setMimeData(mime_data)
drag.setPixmap(self.grab(self.rect()))
if event.modifiers() == Qt.ControlModifier:
drag.exec_(Qt.MoveAction)
else:
drag.exec_(Qt.CopyAction)
event.accept()
else:
event.ignore()
示例15: mousePressEvent
# 需要导入模块: from PyQt5.QtGui import QDrag [as 别名]
# 或者: from PyQt5.QtGui.QDrag import setPixmap [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()