本文整理汇总了Python中PyQt5.Qt.QDrag类的典型用法代码示例。如果您正苦于以下问题:Python QDrag类的具体用法?Python QDrag怎么用?Python QDrag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDrag类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouseMoveEvent
def mouseMoveEvent(self, event):
dex = self.indexAt(event.pos())
if dex.isValid():
self.setCursor(Qt.PointingHandCursor)
else:
self.unsetCursor()
if not event.buttons() & Qt.LeftButton:
return
if self.in_drag_drop or not dex.isValid():
QTreeView.mouseMoveEvent(self, event)
return
# Must deal with odd case where the node being dragged is 'virtual',
# created to form a hierarchy. We can't really drag this node, but in
# addition we can't allow drag recognition to notice going over some
# other node and grabbing that one. So we set in_drag_drop to prevent
# this from happening, turning it off when the user lifts the button.
self.in_drag_drop = True
if not self._model.flags(dex) & Qt.ItemIsDragEnabled:
QTreeView.mouseMoveEvent(self, event)
return
md = self._model.mimeData([dex])
pixmap = dex.data(DRAG_IMAGE_ROLE).pixmap(self.iconSize())
drag = QDrag(self)
drag.setPixmap(pixmap)
drag.setMimeData(md)
if self._model.is_in_user_category(dex):
drag.exec_(Qt.CopyAction|Qt.MoveAction, Qt.CopyAction)
else:
drag.exec_(Qt.CopyAction)
示例2: __init__
def __init__(self, parent, url = ''):
super(WebView, self).__init__(parent)
self.draging = False
self.drag = QDrag(self)
self.webPage = WebPage()
self.setPage(self.webPage)
self.mainFrame = self.page().mainFrame()
self.setAttribute(Qt.WA_DeleteOnClose, True)
self.titleChanged.connect(parent.setWindowTitle)
self.load(url)
webSettings = self.settings()
webSettings.setDefaultTextEncoding("utf-8")
# webSettings.setOfflineStorageDefaultQuota(sys.maxsize)
# webSettings.setOfflineWebApplicationCacheQuota(sys.maxsize)
webSettings.enablePersistentStorage(assets.fs.dataPath())
webSettings.setAttribute(QWebSettings.PluginsEnabled, True)
webSettings.setAttribute(QWebSettings.DnsPrefetchEnabled, True)
webSettings.setAttribute(QWebSettings.XSSAuditingEnabled, True)
webSettings.setAttribute(QWebSettings.CSSGridLayoutEnabled, True)
webSettings.setAttribute(QWebSettings.ScrollAnimatorEnabled, True)
webSettings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
webSettings.setAttribute(QWebSettings.JavascriptCanOpenWindows, True)
webSettings.setAttribute(QWebSettings.JavascriptCanCloseWindows, True)
webSettings.setAttribute(QWebSettings.JavascriptCanAccessClipboard, True)
webSettings.setAttribute(QWebSettings.LocalContentCanAccessFileUrls, True)
webSettings.setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True)
self.mainFrame.javaScriptWindowObjectCleared.connect(self.setJavaScriptObject)
self.mainFrame.iconChanged.connect(self.changeIcon)
示例3: drag_data
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
示例4: drag_data
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
示例5: WebView
class WebView(QWebView):
def __init__(self, parent, url = ''):
super(WebView, self).__init__(parent)
self.draging = False
self.drag = QDrag(self)
self.webPage = WebPage()
self.setPage(self.webPage)
self.mainFrame = self.page().mainFrame()
self.setAttribute(Qt.WA_DeleteOnClose, True)
self.titleChanged.connect(parent.setWindowTitle)
self.load(url)
webSettings = self.settings()
webSettings.setDefaultTextEncoding("utf-8")
# webSettings.setOfflineStorageDefaultQuota(sys.maxsize)
# webSettings.setOfflineWebApplicationCacheQuota(sys.maxsize)
webSettings.enablePersistentStorage(assets.fs.dataPath())
webSettings.setAttribute(QWebSettings.PluginsEnabled, True)
webSettings.setAttribute(QWebSettings.DnsPrefetchEnabled, True)
webSettings.setAttribute(QWebSettings.XSSAuditingEnabled, True)
webSettings.setAttribute(QWebSettings.CSSGridLayoutEnabled, True)
webSettings.setAttribute(QWebSettings.ScrollAnimatorEnabled, True)
webSettings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
webSettings.setAttribute(QWebSettings.JavascriptCanOpenWindows, True)
webSettings.setAttribute(QWebSettings.JavascriptCanCloseWindows, True)
webSettings.setAttribute(QWebSettings.JavascriptCanAccessClipboard, True)
webSettings.setAttribute(QWebSettings.LocalContentCanAccessFileUrls, True)
webSettings.setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True)
self.mainFrame.javaScriptWindowObjectCleared.connect(self.setJavaScriptObject)
self.mainFrame.iconChanged.connect(self.changeIcon)
def load(self, url = ''):
p = re.compile('(^file:\/\/)|(^http:\/\/)|(^https:\/\/)|(^data:)')
if url and p.match(url) == None:
url = QUrl.fromLocalFile(os.path.abspath(url))
else:
url = QUrl(url)
super(WebView, self).load(url)
def eval(self, javaScript):
return self.mainFrame.evaluateJavaScript(javaScript)
def changeIcon(self):
self.parentWidget().setWindowIcon(self.mainFrame.icon())
# self.parentWidget().setWindowIcon(QWebSettings.iconForUrl(self.url()))
def setJavaScriptObject(self):
self.mainFrame.addToJavaScriptWindowObject('HAE', self.parentWidget().api)
self.mainFrame.addToJavaScriptWindowObject('HAE_app', self.parentWidget())
self.mainFrame.addToJavaScriptWindowObject('HAE_fs', assets.fs)
self.mainFrame.addToJavaScriptWindowObject('HAE_sys', assets.sys)
self.mainFrame.addToJavaScriptWindowObject('HAE_codec', assets.codec)
self.eval('''
(function(){
initModule('fs');
initModule('sys');
initModule('app');
initModule('codec');
initClass('Window');
initClass('Dialog');
initClass('FileDialog');
initClass('File');
initClass('Menu');
initClass('MenuItem');
initClass('TrayIcon');
initClass('Downloader');
initClass('Process');
initClass('SocketServer');
initClass('SocketClient');
function initClass(name){
HAE[name] = function(){
return initEventBinder(HAE['create' + name].apply(window, arguments));
};
}
function initModule(name){
var key = 'HAE_' + name;
HAE[name] = initEventBinder(window[key]);
delete window[key];
}
function initEventBinder(object){
object.addEvent = function(event, handler){
if(typeof event == 'string'){
var eventName = event;
event = ('on' + event).toLowerCase();
if(event in this && this[event].connect){
this[event].connect(handler);
}else{
console.warn('Warning: This object dose not have "' + eventName + '" event');
}
}else if(typeof event == 'object'){
for(var key in event){
this.addEvent(key, event[key]);
}
}
};
object.removeEvent = function(event, handler){
event = 'on' + event;
console.log(this[event]);
if(event in this && this[event].connect){
this[event].disconnect(handler);
}
#.........这里部分代码省略.........