當前位置: 首頁>>代碼示例>>Python>>正文


Python QDrag.exec方法代碼示例

本文整理匯總了Python中PyQt5.Qt.QDrag.exec方法的典型用法代碼示例。如果您正苦於以下問題:Python QDrag.exec方法的具體用法?Python QDrag.exec怎麽用?Python QDrag.exec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt5.Qt.QDrag的用法示例。


在下文中一共展示了QDrag.exec方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: WebView

# 需要導入模塊: from PyQt5.Qt import QDrag [as 別名]
# 或者: from PyQt5.Qt.QDrag import exec [as 別名]

#.........這裏部分代碼省略.........
				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);
						}
					};
					return object;
				}
			})();
		''')

	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)
				# self.drag.setPixmap(pixmap)
				# self.drag.setHotSpot(QPoint(self.drag.pixmap().width() / 2, self.drag.pixmap().height() / 2))

	def mouseMoveEvent(self, event):
		if not self.parentWidget().isDraging():
			super(WebView, self).mouseMoveEvent(event)
			if self.drag.mimeData():
				self.drag.exec()
				self.drag.setMimeData(None)
		if not self.draging:
			event.ignore()

	def mouseReleaseEvent(self, event):
		self.draging = False
		super(WebView, self).mouseReleaseEvent(event)
		self.drag.setMimeData(None)
		event.ignore()

	def close(self):
		self.stop()
		self.load()
		self.page().close()
		self.eval('HAE = null')
		self.drag.setMimeData(None)
		super(WebView, self).close()
開發者ID:andriodartisan,項目名稱:hae,代碼行數:104,代碼來源:webview.py


注:本文中的PyQt5.Qt.QDrag.exec方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。