当前位置: 首页>>代码示例>>C++>>正文


C++ QWebPage::settings方法代码示例

本文整理汇总了C++中QWebPage::settings方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebPage::settings方法的具体用法?C++ QWebPage::settings怎么用?C++ QWebPage::settings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QWebPage的用法示例。


在下文中一共展示了QWebPage::settings方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: attachAndDestroy

void tst_QWebInspector::attachAndDestroy()
{
    {   // External inspector + manual destruction of page first
        QWebPage* page = new QWebPage();
        page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
        QWebInspector* inspector = new QWebInspector();
        inspector->setPage(page);
        page->updatePositionDependentActions(QPoint(0, 0));
        page->triggerAction(QWebPage::InspectElement);

        delete page;
        delete inspector;
    }
    {   // External inspector + manual destruction of inspector first
        QWebPage* page = new QWebPage();
        page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
        QWebInspector* inspector = new QWebInspector();
        inspector->setPage(page);
        page->updatePositionDependentActions(QPoint(0, 0));
        page->triggerAction(QWebPage::InspectElement);

        delete inspector;
        delete page;
    }
    {   // Internal inspector
        QWebPage page;
        page.settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
        page.updatePositionDependentActions(QPoint(0, 0));
        page.triggerAction(QWebPage::InspectElement);
    }
}
开发者ID:achellies,项目名称:WinCEWebKit,代码行数:31,代码来源:tst_qwebinspector.cpp

示例2: QString

void
message_view::prepend_body_fragment(const QString& fragment)
{
  QWebPage* page = m_bodyv->page();
  page->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
  QString js = QString("try {var b=document.getElementsByTagName('body')[0]; var p=document.createElement('div'); p.innerHTML=\"%1\"; b.insertBefore(p, b.firstChild); 1;} catch(e) { e; }").arg(escape_js_string(fragment));
  QVariant v = page->mainFrame()->evaluateJavaScript(js);
  page->settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例3: getEntryItemsFromHtml

static QWebElementCollection getEntryItemsFromHtml(const QString &html)
{
    QWebPage webPage;
    // disable JavaScript and rendering of external object
    webPage.settings()->setAttribute(QWebSettings::AutoLoadImages, false);
    webPage.settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
    webPage.settings()->setAttribute(QWebSettings::PrintElementBackgrounds, false);
    webPage.settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, false);
    webPage.settings()->setAttribute(QWebSettings::LocalContentCanAccessFileUrls, false);

    webPage.mainFrame()->setHtml(html);
    return webPage.mainFrame()->findAllElements("article");
}
开发者ID:b0bben,项目名称:GagBook,代码行数:13,代码来源:ninegagrequest.cpp

示例4: settings

QWebSettings* QWebPageProto::settings() const
{
  QWebPage *item = qscriptvalue_cast<QWebPage*>(thisObject());
  if (item)
    return item->settings();
  return 0;
}
开发者ID:dwatson78,项目名称:qt-client,代码行数:7,代码来源:qwebpageproto.cpp

示例5: setupInspector

void WebkitShow::setupInspector()
{
    QWebPage* webpage = view->page();
    webpage->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    webInspector->setPage(webpage);

    QShortcut* shortCut = new QShortcut(this);
    shortCut->setKey(Qt::Key_F12);
    connect(shortCut, SIGNAL(activated()), this, SLOT(toggleInspector()));
}
开发者ID:Iownnoname,项目名称:qt,代码行数:10,代码来源:webkitshow.cpp

示例6: onGetLyricPageResult

void LyricsManiaAPI::onGetLyricPageResult()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender());

    bool found = false;
    Lyric* lyric = 0;

    if (reply->error() != QNetworkReply::NoError) {
        qCritical() << "Cannot fetch lyric";
    } else {
        QWebPage page;
        page.settings()->setAttribute(QWebSettings::AutoLoadImages, false);
        page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
        page.mainFrame()->setHtml(reply->readAll());

        QWebElement lyricbox = page.mainFrame()->findFirstElement("div[class=lyrics-body]");

        if (lyricbox.isNull()) {
            qCritical() << "Cannot find lyric text in HTML page";
        } else {
            // Remove the video div
            lyricbox.findFirst(QStringLiteral("div")).removeFromDocument();
            // Remove the song title
            lyricbox.findFirst(QStringLiteral("strong")).removeFromDocument();

            lyric = lyrics.take(reply);

            if (!lyric) {
                qCritical() << "Got an invalid lyric object!";
            } else {
                lyric->setText(lyricbox.toPlainText());

                found = true;
            }
        }
    }

    qDebug() << "Lyric found:" << found;
    Q_EMIT lyricFetched(lyric, found);

    reply->deleteLater();
}
开发者ID:Quent-in,项目名称:harbour-Lyrics,代码行数:42,代码来源:lyricsmaniaapi.cpp

示例7: import

bool HtmlBookmarksImporter::import(const QString &path)
{
#ifdef OTTER_ENABLE_QTWEBKIT
	QFile file(getSuggestedPath(path));

	if (!file.open(QIODevice::ReadOnly))
	{
		emit importFinished(BookmarksImport, FailedImport, 0);

		return false;
	}

	if (m_optionsWidget)
	{
		if (m_optionsWidget->hasToRemoveExisting())
		{
			removeAllBookmarks();

			if (m_optionsWidget->isImportingIntoSubfolder())
			{
				setImportFolder(BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, {{BookmarksModel::TitleRole, m_optionsWidget->getSubfolderName()}}));
			}
		}
		else
		{
			setAllowDuplicates(m_optionsWidget->areDuplicatesAllowed());
			setImportFolder(m_optionsWidget->getTargetFolder());
		}
	}

	QWebPage page;
	page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
	page.mainFrame()->setHtml(file.readAll());

	m_totalAmount = page.mainFrame()->findAllElements(QLatin1String("dt, hr")).count();

	emit importStarted(BookmarksImport, m_totalAmount);

	BookmarksManager::getModel()->beginImport(getImportFolder(), page.mainFrame()->findAllElements(QLatin1String("a[href]")).count(), page.mainFrame()->findAllElements(QLatin1String("a[shortcuturl]")).count());

	processElement(page.mainFrame()->documentElement().findFirst(QLatin1String("dl")));

	BookmarksManager::getModel()->endImport();

	emit importFinished(BookmarksImport, SuccessfullImport, m_totalAmount);

	file.close();

	return true;
#else
	return false;
#endif
}
开发者ID:haydara,项目名称:otter,代码行数:53,代码来源:HtmlBookmarksImporter.cpp

示例8: webPageSelected

void WebInspector::webPageSelected(int index)
{
  QObject *obj =
    ui->webPageComboBox->itemData(index, ObjectModel::ObjectRole).value<QObject*>();
  QWebPage *page = qobject_cast<QWebPage*>(obj);
  if (page) {
    page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    ui->webInspector->setPage(page);
    // webinspector needs a show event to actually show anything, just setting the page is not enough...
    ui->webInspector->hide();
    ui->webInspector->show();
  }
}
开发者ID:krf,项目名称:GammaRay,代码行数:13,代码来源:webinspector.cpp

示例9: initWebViewAttributes

void MainWindow::initWebViewAttributes()
{
    QWebPage* page = webView->page();

    // 使用系统代理
    QNetworkProxyFactory::setUseSystemConfiguration(true);

    // 设置本地缓存
    QNetworkDiskCache *diskCache = new QNetworkDiskCache(webView);
    QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
    diskCache->setCacheDirectory(location);
    page->networkAccessManager()->setCache(diskCache);
    page->settings()->setMaximumPagesInCache(100);
}
开发者ID:yxq198514,项目名称:berserkJS,代码行数:14,代码来源:mainwindow.cpp

示例10: installedPlugins

void tst_QWebPluginDatabase::installedPlugins()
{
    QWebPage page;
    page.settings()->setAttribute(QWebSettings::PluginsEnabled, true);
    QWebFrame* frame = page.mainFrame();

    QVariantMap jsPluginsMap = frame->evaluateJavaScript("window.navigator.plugins").toMap();
    QList<QWebPluginInfo> plugins = QWebSettings::pluginDatabase()->plugins();
    QCOMPARE(plugins, QWebSettings::pluginDatabase()->plugins());

    int length = jsPluginsMap["length"].toInt();
    QCOMPARE(length, plugins.count());

    for (int i = 0; i < length; ++i) {
        QWebPluginInfo plugin = plugins.at(i);

        QVariantMap jsPlugin = frame->evaluateJavaScript(QString("window.navigator.plugins[%1]").arg(i)).toMap();
        QString name = jsPlugin["name"].toString();
        QString description = jsPlugin["description"].toString();
        QString fileName = jsPlugin["filename"].toString();

        QCOMPARE(plugin.name(), name);
        QCOMPARE(plugin.description(), description);
        QCOMPARE(QFileInfo(plugin.path()).fileName(), fileName);

        QList<MimeType> mimeTypes;
        int mimeTypesCount = jsPlugin["length"].toInt();

        for (int j = 0; j < mimeTypesCount; ++j) {
            QVariantMap jsMimeType = frame->evaluateJavaScript(QString("window.navigator.plugins[%1][%2]").arg(i).arg(j)).toMap();

            MimeType mimeType;
            mimeType.name = jsMimeType["type"].toString();
            mimeType.description = jsMimeType["description"].toString();
            mimeType.fileExtensions = jsMimeType["suffixes"].toString().split(',', QString::SkipEmptyParts);

            mimeTypes.append(mimeType);
            QVERIFY(plugin.supportsMimeType(mimeType.name));
        }

        QCOMPARE(plugin.mimeTypes(), mimeTypes);

        QVERIFY(!plugin.isNull());
        QVERIFY(plugin.isEnabled());
    }
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:46,代码来源:tst_qwebplugindatabase.cpp

示例11: paint

void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
  Q_UNUSED( itemStyle );
  Q_UNUSED( pWidget );
  if ( !painter )
  {
    return;
  }
  if ( !shouldDrawItem() )
  {
    return;
  }

  drawBackground( painter );
  painter->save();

  //antialiasing on
  painter->setRenderHint( QPainter::Antialiasing, true );

  double penWidth = hasFrame() ? pen().widthF() : 0;
  QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin, rect().height() - 2 * penWidth - 2 * mMargin );

  QString textToDraw = displayText();

  if ( mHtmlState )
  {
    painter->scale( 1.0 / mHtmlUnitsToMM / 10.0, 1.0 / mHtmlUnitsToMM / 10.0 );
    QWebPage *webPage = new QWebPage();
    webPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() );

    //Setup event loop and timeout for rendering html
    QEventLoop loop;
    QTimer timeoutTimer;
    timeoutTimer.setSingleShot( true );

    //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/
    QPalette palette = webPage->palette();
    palette.setBrush( QPalette::Base, Qt::transparent );
    webPage->setPalette( palette );
    //webPage->setAttribute(Qt::WA_OpaquePaintEvent, false); //this does not compile, why ?

    webPage->setViewportSize( QSize( painterRect.width() * mHtmlUnitsToMM * 10.0, painterRect.height() * mHtmlUnitsToMM * 10.0 ) );
    webPage->mainFrame()->setZoomFactor( 10.0 );
    webPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
    webPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );

    // QGIS segfaults when rendering web page while in composer if html
    // contains images. So if we are not printing the composition, then
    // disable image loading
    if ( mComposition->plotStyle() != QgsComposition::Print &&
         mComposition->plotStyle() != QgsComposition::Postscript )
    {
      webPage->settings()->setAttribute( QWebSettings::AutoLoadImages, false );
    }

    //Connect timeout and webpage loadFinished signals to loop
    connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
    connect( webPage, SIGNAL( loadFinished( bool ) ), &loop, SLOT( quit() ) );

    //mHtmlLoaded tracks whether the QWebPage has completed loading
    //its html contents, set it initially to false. The loadingHtmlFinished slot will
    //set this to true after html is loaded.
    mHtmlLoaded = false;
    connect( webPage, SIGNAL( loadFinished( bool ) ), SLOT( loadingHtmlFinished( bool ) ) );

    webPage->mainFrame()->setHtml( textToDraw );

    //For very basic html labels with no external assets, the html load will already be
    //complete before we even get a chance to start the QEventLoop. Make sure we check
    //this before starting the loop
    if ( !mHtmlLoaded )
    {
      // Start a 20 second timeout in case html loading will never complete
      timeoutTimer.start( 20000 );
      // Pause until html is loaded
      loop.exec();
    }
    webPage->mainFrame()->render( painter );//DELETE WEBPAGE ?
  }
  else
  {
开发者ID:baditaflorin,项目名称:QGIS,代码行数:81,代码来源:qgscomposerlabel.cpp

示例12: main

int main(int argc, char **argv)
{
    // Qt requires that we construct the global QApplication before creating any widgets.
    QApplication app(argc, argv);

    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

    // true = run osgViewer in a separate thread than Qt
    // false = interleave osgViewer and Qt in the main thread
    bool useFrameLoopThread = false;
    if (arguments.read("--no-frame-thread")) useFrameLoopThread = false;
    if (arguments.read("--frame-thread")) useFrameLoopThread = true;

    // true = use QWidgetImage
    // false = use QWebViewImage
    bool useWidgetImage = false;
    if (arguments.read("--useWidgetImage")) useWidgetImage = true;

    // true = use QWebView in a QWidgetImage to compare to QWebViewImage
    // false = make an interesting widget
    bool useBrowser = false;
    if (arguments.read("--useBrowser")) useBrowser = true;

    // true = use a QLabel for text
    // false = use a QTextEdit for text
    // (only applies if useWidgetImage == true and useBrowser == false)
    bool useLabel = false;
    if (arguments.read("--useLabel")) useLabel = true;

    // true = make a Qt window with the same content to compare to
    // QWebViewImage/QWidgetImage
    // false = use QWebViewImage/QWidgetImage (depending on useWidgetImage)
    bool sanityCheck = false;
    if (arguments.read("--sanityCheck")) sanityCheck = true;

    // Add n floating windows inside the QGraphicsScene.
    int numFloatingWindows = 0;
    while (arguments.read("--numFloatingWindows", numFloatingWindows));

    // true = Qt widgets will be displayed on a quad inside the 3D scene
    // false = Qt widgets will be an overlay over the scene (like a HUD)
    bool inScene = true;
    if (arguments.read("--fullscreen")) { inScene = false; }


    osg::ref_ptr<osg::Group> root = new osg::Group;

    if (!useWidgetImage)
    {
        //-------------------------------------------------------------------
        // QWebViewImage test
        //-------------------------------------------------------------------
        // Note: When the last few issues with QWidgetImage are fixed,
        // QWebViewImage and this if() {} section can be removed since
        // QWidgetImage can display a QWebView just like QWebViewImage. Use
        // --useWidgetImage --useBrowser to see that in action.

        if (!sanityCheck)
        {
            osg::ref_ptr<osgQt::QWebViewImage> image = new osgQt::QWebViewImage;

            if (arguments.argc()>1) image->navigateTo((arguments[1]));
            else image->navigateTo("http://www.openscenegraph.org/");

            osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f),
                                           osg::Vec3(1.0f,0.0f,0.0f),
                                           osg::Vec3(0.0f,0.0f,1.0f),
                                           osg::Vec4(1.0f,1.0f,1.0f,1.0f),
                                           osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO);

            osg::ref_ptr<osgWidget::Browser> browser = new osgWidget::Browser;
            browser->assign(image.get(), hints);

            root->addChild(browser.get());
        }
        else
        {
            // Sanity check, do the same thing as QGraphicsViewAdapter but in
            // a separate Qt window.
            QWebPage* webPage = new QWebPage;
            webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
            webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true);

            QWebView* webView = new QWebView;
            webView->setPage(webPage);

            if (arguments.argc()>1) webView->load(QUrl(arguments[1]));
            else webView->load(QUrl("http://www.openscenegraph.org/"));

            QGraphicsScene* graphicsScene = new QGraphicsScene;
            graphicsScene->addWidget(webView);

            QGraphicsView* graphicsView = new QGraphicsView;
            graphicsView->setScene(graphicsScene);

            QMainWindow* mainWindow = new QMainWindow;
            //mainWindow->setLayout(new QVBoxLayout);
            mainWindow->setCentralWidget(graphicsView);
            mainWindow->setGeometry(50, 50, 1024, 768);
//.........这里部分代码省略.........
开发者ID:yueying,项目名称:osg,代码行数:101,代码来源:osgQtWidgets.cpp


注:本文中的QWebPage::settings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。