本文整理汇总了Python中PyQt5.Qt.QMimeData.setUrls方法的典型用法代码示例。如果您正苦于以下问题:Python QMimeData.setUrls方法的具体用法?Python QMimeData.setUrls怎么用?Python QMimeData.setUrls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QMimeData
的用法示例。
在下文中一共展示了QMimeData.setUrls方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mousePressEvent
# 需要导入模块: from PyQt5.Qt import QMimeData [as 别名]
# 或者: from PyQt5.Qt.QMimeData import setUrls [as 别名]
def mousePressEvent(self, event):
self.parentWidget().mousePressEvent(event)
if not self.parentWidget().isDraging():
super(WebView, self).mousePressEvent(event)
if event.buttons() == Qt.LeftButton:
mimeData = QMimeData()
hitTestResult = self.mainFrame.hitTestContent(event.pos())
# print(hitTestResult.linkUrl())
# dragging the scrollbar
if hitTestResult.isNull():
self.draging = True
if hitTestResult.isContentSelected():
mimeData.setText(self.selectedText())
mimeData.setHtml(self.selectedHtml())
elif not hitTestResult.linkUrl().isEmpty():
mimeData.setUrls([hitTestResult.linkUrl()])
mimeData.setHtml(hitTestResult.element().toOuterXml())
elif not hitTestResult.pixmap().isNull():
mimeData.setImageData(hitTestResult.pixmap())
mimeData.setUrls([hitTestResult.imageUrl()])
mimeData.setHtml(hitTestResult.element().toOuterXml())
# mimeData.setData('application/x-qt-windows-mime;value="FileContents"', QVariant(hitTestResult.pixmap()).toByteArray())
# elif not hitTestResult.mediaUrl().isEmpty():
# mimeData.setUrls([hitTestResult.mediaUrl()])
# mimeData.setHtml(hitTestResult.element().toOuterXml())
else:
return
# pixmap = hitTestResult.pixmap()
# pixmap.setMask(QBitmap.fromImage(pixmap.toImage()))
self.drag.setMimeData(mimeData)
示例2: drag_data
# 需要导入模块: from PyQt5.Qt import QMimeData [as 别名]
# 或者: from PyQt5.Qt.QMimeData import setUrls [as 别名]
def drag_data(self):
m = self.model()
rows = self.selectionModel().selectedRows()
paths = [force_unicode(p, enc=filesystem_encoding) for p in m.paths(rows) if p]
md = QMimeData()
md.setData("application/calibre+from_device", b"dummy")
md.setUrls([QUrl.fromLocalFile(p) for p in paths])
drag = QDrag(self)
drag.setMimeData(md)
cover = self.drag_icon(m.cover(self.currentIndex().row()), len(paths) > 1)
drag.setHotSpot(QPoint(-15, -15))
drag.setPixmap(cover)
return drag
示例3: drag_data
# 需要导入模块: from PyQt5.Qt import QMimeData [as 别名]
# 或者: from PyQt5.Qt.QMimeData import setUrls [as 别名]
def drag_data(self):
m = self.model()
db = m.db
selected = self.get_selected_ids()
ids = ' '.join(map(str, selected))
md = QMimeData()
md.setData('application/calibre+from_library', ids.encode('utf-8'))
fmt = prefs['output_format']
def url_for_id(i):
try:
ans = db.format_path(i, fmt, index_is_id=True)
except:
ans = None
if ans is None:
fmts = db.formats(i, index_is_id=True)
if fmts:
fmts = fmts.split(',')
else:
fmts = []
for f in fmts:
try:
ans = db.format_path(i, f, index_is_id=True)
except:
ans = None
if ans is None:
ans = db.abspath(i, index_is_id=True)
return QUrl.fromLocalFile(ans)
md.setUrls([url_for_id(i) for i in selected])
drag = QDrag(self)
col = self.selectionModel().currentIndex().column()
try:
md.column_name = self.column_map[col]
except AttributeError:
md.column_name = 'title'
drag.setMimeData(md)
cover = self.drag_icon(m.cover(self.currentIndex().row()),
len(selected) > 1)
drag.setHotSpot(QPoint(-15, -15))
drag.setPixmap(cover)
return drag