本文整理汇总了Python中PyQt5.QtCore.QMimeData.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QMimeData.setData方法的具体用法?Python QMimeData.setData怎么用?Python QMimeData.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QMimeData
的用法示例。
在下文中一共展示了QMimeData.setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMove
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def testMove(self):
w = self.newWidget()
item = w._path_item_map.get("/Variables/u")
#b = w.tree.getBlockInfo("/Variables/u")
w.scrollToItem(item)
point = w.visualItemRect(item).center()
item1 = w._path_item_map.get("/Variables/v")
#b1 = w.tree.getBlockInfo("/Variables/v")
w.scrollToItem(item1)
point1 = w.visualItemRect(item1).bottomLeft()
#idx = b.parent.children_list.index(b.name)
#idx1 = b.parent.children_list.index(b1.name)
w.setCurrentItem(item)
mime = QMimeData()
mime.setData(w._mime_type, "some data")
ee = QDragEnterEvent(w.mapToGlobal(point), Qt.MoveAction, mime, Qt.LeftButton, Qt.NoModifier)
w.dragEnterEvent(ee)
#Testing.process_events(t=1)
de = QDropEvent(w.mapToGlobal(point1), Qt.MoveAction, mime, Qt.LeftButton, Qt.NoModifier)
w.dropEvent(de)
# This doesn't seem to work for some reason
#self.assertEqual(idx1, b.parent.children_list.index(b.name))
#self.assertEqual(idx, b.parent.children_list.index(b1.name))
w.setCurrentItem(None)
self.assertEqual(w._current_drag, None)
w.dropEvent(de)
w.dragEnterEvent(ee)
self.assertEqual(w._current_drag, None)
w.setCurrentItem(item1)
w.dragEnterEvent(ee)
self.assertNotEqual(w._current_drag, None)
w.dropEvent(de)
示例2: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [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()
示例3: mousePressEvent
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [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: mimeData
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
"""
Public method to return the mime data.
@param indexes list of indexes (QModelIndexList)
@return mime data (QMimeData)
"""
from .XbelWriter import XbelWriter
data = QByteArray()
stream = QDataStream(data, QIODevice.WriteOnly)
urls = []
for index in indexes:
if index.column() != 0 or not index.isValid():
continue
encodedData = QByteArray()
buffer = QBuffer(encodedData)
buffer.open(QIODevice.ReadWrite)
writer = XbelWriter()
parentNode = self.node(index)
writer.write(buffer, parentNode)
stream << encodedData
urls.append(index.data(self.UrlRole))
mdata = QMimeData()
mdata.setData(self.MIMETYPE, data)
mdata.setUrls(urls)
return mdata
示例5: mousePressEvent
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def mousePressEvent(self, event):
mime = QMimeData()
itemData = QByteArray()
mime.setData('application/x-dnditemdata', itemData)
drag = QDrag(self)
drag.setMimeData(mime)
drag.exec_(Qt.MoveAction)
示例6: mimeData
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
"""See QAbstractItemModel documentation"""
if len(indexes) != 1:
return 0
data = QMimeData()
data.setData(self.mimeTypes()[0], QByteArray.number(indexes[0].row()))
return data
示例7: copy
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def copy(self):
"""Copy to the clipboard"""
data = QMimeData()
text = '\n'.join([cursor.selectedText() \
for cursor in self.cursors()])
data.setText(text)
data.setData(self.MIME_TYPE, text.encode('utf8'))
QApplication.clipboard().setMimeData(data)
示例8: mimeData
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def mimeData(self, index_list):
data = QMimeData()
g_list = []
for idx in index_list:
g = idx.data(GalleryModel.GALLERY_ROLE)
if g != None:
g_list.append(g)
data.setData("list/gallery", QByteArray(pickle.dumps(g_list)))
return data
示例9: mimeData
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
mimeData = QMimeData()
encodedData = QByteArray()
stream = QDataStream(encodedData, QIODevice.WriteOnly)
for index in indexes:
if (index.isValid()):
stream.writeInt(self.tileIndexAt(index))
mimeData.setData(TILES_MIMETYPE, encodedData)
return mimeData
示例10: copyOutlines
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def copyOutlines(self):
glyph = self.view.glyph()
clipboard = QApplication.clipboard()
mimeData = QMimeData()
copyGlyph = glyph.getRepresentation("defconQt.FilterSelection")
mimeData.setData("application/x-defconQt-glyph-data",
pickle.dumps([copyGlyph.serialize(
blacklist=("name", "unicode")
)]))
clipboard.setMimeData(mimeData)
示例11: mousePressEvent
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def mousePressEvent(self, me):
if me.button() == Qt.LeftButton:
child = self.find_label()
if child != None:
mime_data = QMimeData()
mime_data.setData('text/plain', child.get_text())
drag = QDrag(self)
drag.setMimeData(mime_data)
#drag.setHotSpot(child.pos())
drag_action = drag.exec_(Qt.CopyAction | Qt.MoveAction)
示例12: mimeData
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
dataList = []
index = indexes[0]
for index in indexes:
path = self.pathForIndex(index)
data = ','.join(map(str, path))
dataList.append(data)
data = '|'.join(dataList)
mimeData = QMimeData()
mimeData.setData(MIME_NODEPATHS, QByteArray(data.encode()))
return mimeData
示例13: copy
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def copy(self):
glyphs = self.glyphCellView.glyphs()
pickled = []
for index in sorted(self.glyphCellView.selection()):
pickled.append(glyphs[index].serialize(
blacklist=("name", "unicode")
))
clipboard = QApplication.clipboard()
mimeData = QMimeData()
mimeData.setData("application/x-trufont-glyph-data",
pickle.dumps(pickled))
clipboard.setMimeData(mimeData)
示例14: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [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()
示例15: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setData [as 别名]
def mouseMoveEvent(self, event):
"""
Protected method to handle mouse move events.
@param event reference to the mouse move event (QMouseEvent)
"""
if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \
(event.pos() - self.__dragStartPos).manhattanLength() > \
QApplication.startDragDistance():
drag = QDrag(self)
mimeData = QMimeData()
index = self.tabAt(event.pos())
mimeData.setText(self.tabText(index))
mimeData.setData("action", b"tab-reordering")
mimeData.setData("tabbar-id", str(id(self)).encode("utf-8"))
mimeData.setData(
"source-index",
QByteArray.number(self.tabAt(self.__dragStartPos)))
mimeData.setData(
"tabwidget-id",
str(id(self.parentWidget())).encode("utf-8"))
drag.setMimeData(mimeData)
if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier):
drag.exec_(Qt.DropActions(Qt.CopyAction))
elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier):
drag.exec_(Qt.DropActions(Qt.MoveAction))
super(TabBar, self).mouseMoveEvent(event)