本文整理汇总了Python中PyQt5.QtGui.QDrag方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QDrag方法的具体用法?Python QtGui.QDrag怎么用?Python QtGui.QDrag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui
的用法示例。
在下文中一共展示了QtGui.QDrag方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouseMoveEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [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()
示例2: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def __init__(self, parent=None):
super(DragButton, self).__init__(parent)
# def mouseMoveEvent(self, event):
# self.startDrag()
# QtWidgets.QToolButton.mouseMoveEvent(self, event)
# def startDrag(self):
# if self.icon().isNull():
# return
# data = QtCore.QByteArray()
# stream = QtCore.QDataStream(data, QtCore.QIODevice.WriteOnly)
# stream << self.icon()
# mimeData = QtCore.QMimeData()
# mimeData.setData("application/x-equipment", data)
# drag = QtGui.QDrag(self)
# drag.setMimeData(mimeData)
# pixmap = self.icon().pixmap(24, 24)
# drag.setHotSpot(QtCore.QPoint(12, 12))
# drag.setPixmap(pixmap)
# drag.exec_(QtCore.Qt.CopyAction)
示例3: mouseMoveEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def mouseMoveEvent(self, mouseEvent):
"""
Executed when the mouse if moved while a button is being pressed.
:type mouseEvent: QMouseEvent
"""
if mouseEvent.buttons() & QtCore.Qt.LeftButton:
if Item.ConceptNode <= self.item < Item.InclusionEdge:
distance = (mouseEvent.pos() - self.startPos).manhattanLength()
if distance >= QtWidgets.QApplication.startDragDistance():
mimeData = QtCore.QMimeData()
mimeData.setText(str(self.item.value))
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.setPixmap(self.icon().pixmap(60, 40))
drag.setHotSpot(self.startPos - self.rect().topLeft())
drag.exec_(QtCore.Qt.CopyAction)
super().mouseMoveEvent(mouseEvent)
示例4: mousePressEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def mousePressEvent(self, event):
child = self.childAt(event.pos())
if not child:
return
mimeData = QMimeData()
mimeData.setText(child.type)
logging.debug('mousePressEvent() called: {}'.format(event.pos()))
drag = QDrag(self)
drag.setPixmap(child.pixmap())
drag.setMimeData(mimeData)
drag.setHotSpot(event.pos() - child.pos())
if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
child.close()
else:
child.show()
child.setPixmap(child.pixmap())
示例5: mousePressEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def mousePressEvent(self, event):
logging.debug('ElementMaster::mousePressEvent() called')
# uncomment this for debugging purpose
#self.listChild()
if event.buttons() != Qt.LeftButton:
return
icon = QLabel()
mimeData = QMimeData()
mime_text = str(self.row) + str(self.column) + str(self.__class__.__name__)
mimeData.setText(mime_text)
drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setPixmap(self.pixmap)
drag.setHotSpot(event.pos() - self.rect().topLeft())
if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
icon.close()
else:
icon.show()
icon.setPixmap(self.pixmap)
示例6: startDrag
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def startDrag(self, supportedActions):
items = self.selectedItems()
drag = QDrag(self)
mimeData = self.mimeData(items)
# 由于QMimeData只能设置image、urls、str、bytes等等不方便
# 这里添加一个额外的属性直接把item放进去,后面可以根据item取出数据
mimeData.setProperty('myItems', items)
drag.setMimeData(mimeData)
pixmap = QPixmap(self.viewport().visibleRegion().boundingRect().size())
pixmap.fill(Qt.transparent)
painter = QPainter()
painter.begin(pixmap)
for item in items:
rect = self.visualRect(self.indexFromItem(item))
painter.drawPixmap(rect, self.viewport().grab(rect))
painter.end()
drag.setPixmap(pixmap)
drag.setHotSpot(self.viewport().mapFromGlobal(QCursor.pos()))
drag.exec_(supportedActions)
示例7: mouseMoveEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def mouseMoveEvent(self, e):
if e.buttons() != Qt.RightButton: # 只操作右键事件
return
mimeData = QMimeData()
drag = QDrag(self) # 创建一个QDrag对象,用来传输MIME-based数据
drag.setMimeData(mimeData)
drag.setHotSpot(e.pos() - self.rect().topLeft())
dropAction = drag.exec_(Qt.MoveAction)
示例8: mousePressEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def mousePressEvent(self, event):
# retrieve the label
child = self.childAt(event.pos())
if not child:
return
self.controller.mode = 'selection'
# update the creation mode to the appropriate subtype
self.controller.creation_mode = child.subtype
pixmap = QPixmap(child.pixmap().scaled(
QSize(50, 50),
Qt.KeepAspectRatio,
Qt.SmoothTransformation
))
mime_data = QtCore.QMimeData()
mime_data.setData('application/x-dnditemdata', QtCore.QByteArray())
drag = QtGui.QDrag(self)
drag.setMimeData(mime_data)
drag.setPixmap(pixmap)
drag.setHotSpot(event.pos() - child.pos() + QPoint(-3, -10))
if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
child.close()
else:
child.show()
示例9: mousePressEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def mousePressEvent(self, event):
# retrieve the label
child = self.childAt(event.pos())
if not child:
return
self.controller.mode = 'selection'
# update the creation mode to the appropriate subtype
self.controller.creation_mode = child.subtype
# we change the view if necessary:
# if it is a site, we switch the site view
# if it is anything else and we are in the site view, we switch
# to the network view
if child.subtype == 'site':
self.project.show_site_view()
else:
if self.project.view_type == 'site':
self.project.show_network_view()
pixmap = QPixmap(child.pixmap().scaled(
QSize(50, 50),
Qt.KeepAspectRatio,
Qt.SmoothTransformation
))
mime_data = QtCore.QMimeData()
mime_data.setData('application/x-dnditemdata', QtCore.QByteArray())
drag = QtGui.QDrag(self)
drag.setMimeData(mime_data)
drag.setPixmap(pixmap)
drag.setHotSpot(event.pos() - child.pos() + QPoint(-3, -10))
if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
child.close()
else:
child.show()
示例10: mousePressEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def mousePressEvent(self, event):
child = self.childAt(event.pos())
if not child:
return
pixmap = QPixmap(child.pixmap())
mimeData = QMimeData()
mimeData.setText(child.type)
drag = QDrag(self)
drag.setPixmap(child.pixmap())
drag.setMimeData(mimeData)
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)
示例11: mousePressEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def mousePressEvent(self, event):
logging.debug('DropBox::mousePressEvent() called: {}'.format(event.pos()))
try:
mimeData = QMimeData()
mimeData.setText(self.type)
# load config into memory tmp_config of storabar
self.parent.tmp_config = self.config
self.parent.tmp_element = self
# push config to active workingarea
self.parent.loadConfig()
except Exception as e:
logging.error('DropBox::mousePressEvent() Exception caught: {}'.format(str(e)))
return
drag = QDrag(self)
drag.setHotSpot(event.pos())
drag.setPixmap(self.label.pixmap())
drag.setMimeData(mimeData)
if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
self.close()
else:
self.show()
self.label.setPixmap(self.label.pixmap())
logging.debug('DropBox::mousePressEvent() dropped')
示例12: startDrag
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def startDrag(self, supportedActions):
selected_items = self.selectedItems()
mimeData = QtCore.QMimeData()
data = []
for item in selected_items:
entry = item.entry
if entry == (-1, -1):
info = {
"name": item.name,
"computation": {},
}
info = json.dumps(info).encode("utf-8")
else:
info = item.name.encode("utf-8")
data.append(
pack(
f"<36s3q{len(info)}s",
str(item.mdf_uuid).encode("ascii"),
entry[0],
entry[1],
len(info),
info,
)
)
mimeData.setData(
"application/octet-stream-asammdf", QtCore.QByteArray(b"".join(data))
)
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.exec(QtCore.Qt.CopyAction)
示例13: startDrag
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QDrag [as 别名]
def startDrag(self, supportedActions):
selected_items = self.selectedItems()
mimeData = QtCore.QMimeData()
data = []
for item in selected_items:
entry = item.entry
computation = item.computation
widget = self.itemWidget(item)
color = widget.color
unit = widget.unit
if entry == (-1, -1):
info = {
"name": item.name,
"computation": computation,
"computed": True,
"unit": unit,
"color": color,
}
info = json.dumps(info).encode("utf-8")
else:
info = item.name.encode("utf-8")
data.append(
pack(
f"<36s3q{len(info)}s",
str(item.mdf_uuid).encode("ascii"),
entry[0],
entry[1],
len(info),
info,
)
)
mimeData.setData(
"application/octet-stream-asammdf", QtCore.QByteArray(b"".join(data))
)
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.exec(QtCore.Qt.CopyAction)