#ifndef BROWSER_H#define BROWSER_H#include <QWidget>#include <QtGui/QIcon>#include <QtCore/QUrl>class QWebView;class browser : public QWidget{ Q_OBJECT public: browser(QWidget *parent = 0); void loadFile(const QString& strFile); private: QWebView *view; };#endif
#include <QtGui>#include <QtCore/QSettings> #include <QtWebKit>#include <QPixmap>#include "browser.h"browser::browser(QWidget *parent): QWidget(parent){ view = new QWebView(this); QHBoxLayout *ley = new QHBoxLayout(); ley->addWidget(view); ley->setMargin(0); ley->setSpacing(0); setLayout(ley); setFixedSize(292,542); }void browser::loadFile(const QString& strFile){ QFile file(strFile); QString strUrl; qDebug() << strFile; if(file.exists()){ strUrl = QString("%1").arg(strFile); qDebug() << "yes file"; }else{ strUrl = QString("http://poumolchaniyu.html"); qDebug() << "no file"; } view->load(QUrl(strUrl)); QSettings settings; settings.beginGroup(QLatin1String("websettings")); QWebSettings *defaultSettings = QWebSettings::globalSettings(); QString standardFontFamily = defaultSettings->fontFamily(QWebSettings::StandardFont); int standardFontSize = defaultSettings->fontSize(QWebSettings::DefaultFontSize); QFont standardFont = QFont(standardFontFamily, standardFontSize); standardFont = qVariantValue<QFont>(settings.value(QLatin1String("standardFont"), standardFont)); defaultSettings->setFontFamily(QWebSettings::StandardFont, standardFont.family()); defaultSettings->setFontSize(QWebSettings::DefaultFontSize, standardFont.pointSize()); QString fixedFontFamily = defaultSettings->fontFamily(QWebSettings::FixedFont); int fixedFontSize = defaultSettings->fontSize(QWebSettings::DefaultFixedFontSize); QFont fixedFont = QFont(fixedFontFamily, fixedFontSize); fixedFont = qVariantValue<QFont>(settings.value(QLatin1String("fixedFont"), fixedFont)); defaultSettings->setFontFamily(QWebSettings::FixedFont, fixedFont.family()); defaultSettings->setFontSize(QWebSettings::DefaultFixedFontSize, fixedFont.pointSize()); defaultSettings->setAttribute(QWebSettings::JavascriptEnabled, settings.value(QLatin1String("enableJavascript"), true).toBool()); defaultSettings->setAttribute(QWebSettings::PluginsEnabled, settings.value(QLatin1String("enablePlugins"), true).toBool()); QUrl url = settings.value(QLatin1String("userStyleSheet")).toUrl(); defaultSettings->setUserStyleSheetUrl(url); settings.endGroup();}
defaultSettings->setAttribute(QWebSettings::PluginsEnabled, settings.value(QLatin1String("enablePlugins"), true).toBool());
возможно, прийдется поиграться с library paths