本文整理汇总了Python中PyQt5.QtCore.QMimeData.setUrls方法的典型用法代码示例。如果您正苦于以下问题:Python QMimeData.setUrls方法的具体用法?Python QMimeData.setUrls怎么用?Python QMimeData.setUrls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QMimeData
的用法示例。
在下文中一共展示了QMimeData.setUrls方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mimeData
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setUrls [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
示例2: dragFile
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setUrls [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)
示例3: mimeData
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setUrls [as 别名]
def mimeData(self, indexes):
"""
Public method to return the mime data.
@param indexes list of indexes (QModelIndexList)
@return mime data (QMimeData)
"""
mimeData = QMimeData()
urls = []
for index in indexes:
if index.isValid():
itm = self.__manager.downloads()[index.row()]
urls.append(QUrl.fromLocalFile(itm.absoluteFilePath()))
mimeData.setUrls(urls)
return mimeData
示例4: mimeData
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setUrls [as 别名]
def mimeData(self, indexes):
"""
Public method to return the mime data.
@param indexes list of indexes (QModelIndexList)
@return mime data (QMimeData)
"""
urls = []
for index in indexes:
url = index.data(HistoryModel.UrlRole)
urls.append(url)
mdata = QMimeData()
mdata.setUrls(urls)
return mdata
示例5: startDrag
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setUrls [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)
示例6: test_EditorPane_drop_event
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setUrls [as 别名]
def test_EditorPane_drop_event():
"""
If there's a drop event associated with files, cause them to be passed into
Mu's existing file loading code.
"""
ep = mu.interface.editor.EditorPane(None, 'baz')
m = mock.MagicMock()
ep.open_file = mock.MagicMock()
ep.open_file.emit = m
data = QMimeData()
data.setUrls([QUrl('file://test/path.py'), QUrl('file://test/path.hex'),
QUrl('file://test/path.txt')])
evt = QDropEvent(QPointF(0, 0), Qt.CopyAction, data,
Qt.LeftButton, Qt.NoModifier)
ep.dropEvent(evt)
# Upstream _load will handle invalid file type (.txt).
assert m.call_count == 3
示例7: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import setUrls [as 别名]
def mouseMoveEvent(self, evt):
"""
Protected method to handle mouse move events.
@param evt reference to the mouse event (QMouseEvent)
"""
if evt.button() == Qt.LeftButton and \
(evt.pos() - self.__dragStartPos).manhattanLength() > \
QApplication.startDragDistance() and \
self.__browser is not None:
drag = QDrag(self)
mimeData = QMimeData()
title = self.__browser.title()
if title == "":
title = str(self.__browser.url().toEncoded(), encoding="utf-8")
mimeData.setText(title)
mimeData.setUrls([self.__browser.url()])
p = self.pixmap()
if p:
drag.setPixmap(p)
drag.setMimeData(mimeData)
drag.exec_()