本文整理汇总了Python中PyQt5.QtCore.QMimeData类的典型用法代码示例。如果您正苦于以下问题:Python QMimeData类的具体用法?Python QMimeData怎么用?Python QMimeData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QMimeData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mousePressEvent
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)
示例2: test_pasteImage_RestructuredText
def test_pasteImage_RestructuredText(self, _mock_image, _mock_editor):
mimeData = QMimeData()
mimeData.setImageData(self._create_image())
self.dummytab.markupClass = ReStructuredTextMarkup
self.editor.insertFromMimeData(mimeData)
self.assertTrue('.. image:: myimage.jpg' in self.editor.toPlainText())
示例3: testMove
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)
示例4: mousePressEvent
def mousePressEvent(self, event):
mime = QMimeData()
itemData = QByteArray()
mime.setData('application/x-dnditemdata', itemData)
drag = QDrag(self)
drag.setMimeData(mime)
drag.exec_(Qt.MoveAction)
示例5: mouseMoveEvent
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()
示例6: test_pasteImage_Markdown
def test_pasteImage_Markdown(self, _mock_image, _mock_editor):
mimeData = QMimeData()
mimeData.setImageData(self._create_image())
self.dummytab.markupClass = MarkdownMarkup
self.editor.insertFromMimeData(mimeData)
self.assertTrue('![myimage](myimage.jpg)' in self.editor.toPlainText())
示例7: mimeData
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
示例8: copy
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)
示例9: mimeData
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
示例10: mimeData
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
示例11: copy_image
def copy_image():
img = QImage()
img.loadFromData(f.read())
data = QMimeData()
data.setImageData(img)
clipboard.setMimeData(data)
print("ok")
示例12: dragFile
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)
示例13: mimeData
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
示例14: copyOutlines
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)
示例15: __dragSnapshot
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)