让你的Pyqt4.QtWebKit支持Flash
其实就是两行代码,先看看我写的!
这是用QT Designer生成的代码,我只是在里面加上了两行自动下载FLASH插件的代码
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file ´E:wwwrootpythonDemoDemo.ui´
#
# Created: Sun Feb 19 09:05:26 2012
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(1024, 768)
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralWidget)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.webView = QtWebKit.QWebView(self.centralWidget)
self.webSettings = self.webView.settings()
self.webSettings.setAttribute(QtWebKit.QWebSettings.PluginsEnabled,True)
self.webView.setUrl(QtCore.QUrl(_fromUtf8("http://xiaomizhou.net/")))
self.webView.setObjectName(_fromUtf8("webView"))
self.verticalLayout.addWidget(self.webView)
self.verticalLayout_2.addLayout(self.verticalLayout)
MainWindow.setCentralWidget(self.centralWidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", u"小米粥", None, QtGui.QApplication.UnicodeUTF8))
from PyQt4 import QtWebKit
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
最关键的就是这两行
self.webSettings = self.webView.settings()
self.webSettings.setAttribute(QtWebKit.QWebSettings.PluginsEnabled,True)