本文整理汇总了C++中QWebSettings::setUserStyleSheetUrl方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebSettings::setUserStyleSheetUrl方法的具体用法?C++ QWebSettings::setUserStyleSheetUrl怎么用?C++ QWebSettings::setUserStyleSheetUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebSettings
的用法示例。
在下文中一共展示了QWebSettings::setUserStyleSheetUrl方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadSettings
void BrowserApplication::loadSettings()
{
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());
int minimumFontSize = settings.value(QLatin1String("minimumFontSize"),
defaultSettings->fontSize(QWebSettings::MinimumFontSize)).toInt();
defaultSettings->setFontSize(QWebSettings::MinimumFontSize, minimumFontSize);
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::JavascriptCanOpenWindows, !(settings.value(QLatin1String("blockPopupWindows"), true).toBool()));
defaultSettings->setAttribute(QWebSettings::JavascriptEnabled, settings.value(QLatin1String("enableJavascript"), true).toBool());
defaultSettings->setAttribute(QWebSettings::PluginsEnabled, settings.value(QLatin1String("enablePlugins"), true).toBool());
defaultSettings->setAttribute(QWebSettings::AutoLoadImages, settings.value(QLatin1String("enableImages"), true).toBool());
defaultSettings->setAttribute(QWebSettings::DeveloperExtrasEnabled, settings.value(QLatin1String("enableInspector"), false).toBool());
QUrl url = settings.value(QLatin1String("userStyleSheet")).toUrl();
defaultSettings->setUserStyleSheetUrl(url);
settings.endGroup();
}
示例2: SetHighlightStyleClass
void MyWebView::SetHighlightStyleClass(QString strClassName, QString &strTmpStyle)
{
QByteArray strComposedStyle("." + strClassName.toUtf8() + " { " + strTmpStyle.toUtf8() + " }");
QWebSettings *settings = QWebSettings::globalSettings();
settings->setUserStyleSheetUrl(QUrl("data:text/css;charset=utf-8;base64," + strComposedStyle.toBase64()));
}
示例3: documentationWidget
QWidget* ManPageDocumentation::documentationWidget(KDevelop::DocumentationFindWidget* findWidget, QWidget* parent )
{
KDevelop::StandardDocumentationView* view = new KDevelop::StandardDocumentationView(findWidget, parent);
view->setDocumentation(IDocumentation::Ptr(this));
// apply custom style-sheet to normalize look of the page
const QString cssFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kdevmanpage/manpagedocumentation.css");
QWebSettings* settings = view->settings();
settings->setUserStyleSheetUrl(QUrl::fromLocalFile(cssFile));
view->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
QObject::connect(view, &KDevelop::StandardDocumentationView::linkClicked, ManPageDocumentation::s_provider->model(), &ManPageModel::showItemFromUrl);
return view;
}
示例4: addCustomStylesheet
void EmbeddedWebView::addCustomStylesheet(const QString &css)
{
m_customCss = css;
QWebSettings *s = settings();
QString bgName, fgName;
QColor bg = palette().color(QPalette::Active, QPalette::Base),
fg = palette().color(QPalette::Active, QPalette::Text);
switch (m_colorScheme) {
case ColorScheme::BlackOnWhite:
bgName = QStringLiteral("white !important");
fgName = QStringLiteral("black !important");
break;
case ColorScheme::AdjustedSystem:
{
// This is HTML, and the authors of that markup are free to specify only the background colors, or only the foreground colors.
// No matter what we pass from outside, there will always be some color which will result in unreadable text, and we can do
// nothing except adding !important everywhere to fix this.
// This code attempts to create a color which will try to produce exactly ugly results for both dark-on-bright and
// bright-on-dark segments of text. However, it's pure alchemy and only a limited heuristics. If you do not like this, please
// submit patches (or talk to the HTML producers, hehehe).
const int v = bg.value();
if (v < 96 && fg.value() > 128 + v/2) {
int h,s,vv,a;
fg.getHsv(&h, &s, &vv, &a) ;
fg.setHsv(h, s, 128+v/2, a);
}
bgName = bg.name();
fgName = fg.name();
break;
}
case ColorScheme::System:
bgName = bg.name();
fgName = fg.name();
break;
}
const QString urlPrefix(QStringLiteral("data:text/css;charset=utf-8;base64,"));
const QString myColors(QStringLiteral("body { background-color: %1; color: %2; }\n").arg(bgName, fgName));
s->setUserStyleSheetUrl(QString::fromUtf8(urlPrefix.toUtf8() + (myColors + m_customCss).toUtf8().toBase64()));
}
示例5: sipNoMethod
static PyObject *meth_QWebSettings_setUserStyleSheetUrl(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
const QUrl* a0;
QWebSettings *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BJ9", &sipSelf, sipType_QWebSettings, &sipCpp, sipType_QUrl, &a0))
{
sipCpp->setUserStyleSheetUrl(*a0);
Py_INCREF(Py_None);
return Py_None;
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QWebSettings, sipName_setUserStyleSheetUrl, doc_QWebSettings_setUserStyleSheetUrl);
return NULL;
}
示例6: loadHtml
void QgsComposerHtml::loadHtml( const bool useCache, const QgsExpressionContext *context )
{
if ( !mWebPage )
{
return;
}
QgsExpressionContext scopedContext = createExpressionContext();
const QgsExpressionContext* evalContext = context ? context : &scopedContext;
QString loadedHtml;
switch ( mContentMode )
{
case QgsComposerHtml::Url:
{
QString currentUrl = mUrl.toString();
//data defined url set?
QVariant exprVal;
if ( dataDefinedEvaluate( QgsComposerObject::SourceUrl, exprVal, *evalContext ) )
{
currentUrl = exprVal.toString().trimmed();
QgsDebugMsg( QString( "exprVal Source Url:%1" ).arg( currentUrl ) );
}
if ( currentUrl.isEmpty() )
{
return;
}
if ( !( useCache && currentUrl == mLastFetchedUrl ) )
{
loadedHtml = fetchHtml( QUrl( currentUrl ) );
mLastFetchedUrl = currentUrl;
}
else
{
loadedHtml = mFetchedHtml;
}
break;
}
case QgsComposerHtml::ManualHtml:
loadedHtml = mHtml;
break;
}
//evaluate expressions
if ( mEvaluateExpressions )
{
loadedHtml = QgsExpression::replaceExpressionText( loadedHtml, evalContext, mDistanceArea );
}
mLoaded = false;
//reset page size. otherwise viewport size increases but never decreases again
mWebPage->setViewportSize( QSize( maxFrameWidth() * mHtmlUnitsToMM, 0 ) );
//set html, using the specified url as base if in Url mode or the project file if in manual mode
const QUrl baseUrl = mContentMode == QgsComposerHtml::Url ?
QUrl( mActualFetchedUrl ) :
QUrl::fromLocalFile( QgsProject::instance()->fileInfo().absoluteFilePath() );
mWebPage->mainFrame()->setHtml( loadedHtml, baseUrl );
//set user stylesheet
QWebSettings* settings = mWebPage->settings();
if ( mEnableUserStylesheet && ! mUserStylesheet.isEmpty() )
{
QByteArray ba;
ba.append( mUserStylesheet.toUtf8() );
QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );
settings->setUserStyleSheetUrl( cssFileURL );
}
else
{
settings->setUserStyleSheetUrl( QUrl() );
}
while ( !mLoaded )
{
qApp->processEvents();
}
//inject JSON feature
if ( !mAtlasFeatureJSON.isEmpty() )
{
mWebPage->mainFrame()->evaluateJavaScript( QString( "if ( typeof setFeature === \"function\" ) { setFeature(%1); }" ).arg( mAtlasFeatureJSON ) );
//needs an extra process events here to give javascript a chance to execute
qApp->processEvents();
}
recalculateFrameSizes();
//trigger a repaint
emit contentsChanged();
}
示例7: loadHtml
void QgsLayoutItemHtml::loadHtml( const bool useCache, const QgsExpressionContext *context )
{
if ( !mWebPage )
{
return;
}
QgsExpressionContext scopedContext = createExpressionContext();
const QgsExpressionContext *evalContext = context ? context : &scopedContext;
QString loadedHtml;
switch ( mContentMode )
{
case QgsLayoutItemHtml::Url:
{
QString currentUrl = mUrl.toString();
//data defined url set?
bool ok = false;
currentUrl = mDataDefinedProperties.valueAsString( QgsLayoutObject::SourceUrl, *evalContext, currentUrl, &ok );
if ( ok )
{
currentUrl = currentUrl.trimmed();
QgsDebugMsg( QString( "exprVal Source Url:%1" ).arg( currentUrl ) );
}
if ( currentUrl.isEmpty() )
{
return;
}
if ( !( useCache && currentUrl == mLastFetchedUrl ) )
{
loadedHtml = fetchHtml( QUrl( currentUrl ) );
mLastFetchedUrl = currentUrl;
}
else
{
loadedHtml = mFetchedHtml;
}
break;
}
case QgsLayoutItemHtml::ManualHtml:
loadedHtml = mHtml;
break;
}
//evaluate expressions
if ( mEvaluateExpressions )
{
loadedHtml = QgsExpression::replaceExpressionText( loadedHtml, evalContext, &mDistanceArea );
}
bool loaded = false;
QEventLoop loop;
connect( mWebPage.get(), &QWebPage::loadFinished, &loop, [&loaded, &loop ] { loaded = true; loop.quit(); } );
connect( mFetcher, &QgsNetworkContentFetcher::finished, &loop, [&loaded, &loop ] { loaded = true; loop.quit(); } );
//reset page size. otherwise viewport size increases but never decreases again
mWebPage->setViewportSize( QSize( maxFrameWidth() * mHtmlUnitsToLayoutUnits, 0 ) );
//set html, using the specified url as base if in Url mode or the project file if in manual mode
const QUrl baseUrl = mContentMode == QgsLayoutItemHtml::Url ?
QUrl( mActualFetchedUrl ) :
QUrl::fromLocalFile( mLayout->project()->fileInfo().absoluteFilePath() );
mWebPage->mainFrame()->setHtml( loadedHtml, baseUrl );
//set user stylesheet
QWebSettings *settings = mWebPage->settings();
if ( mEnableUserStylesheet && ! mUserStylesheet.isEmpty() )
{
QByteArray ba;
ba.append( mUserStylesheet.toUtf8() );
QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );
settings->setUserStyleSheetUrl( cssFileURL );
}
else
{
settings->setUserStyleSheetUrl( QUrl() );
}
if ( !loaded )
loop.exec( QEventLoop::ExcludeUserInputEvents );
//inject JSON feature
if ( !mAtlasFeatureJSON.isEmpty() )
{
mWebPage->mainFrame()->evaluateJavaScript( QStringLiteral( "if ( typeof setFeature === \"function\" ) { setFeature(%1); }" ).arg( mAtlasFeatureJSON ) );
//needs an extra process events here to give JavaScript a chance to execute
qApp->processEvents();
}
recalculateFrameSizes();
//trigger a repaint
emit contentsChanged();
}
示例8: loadHtml
void QgsComposerHtml::loadHtml( const bool useCache, const QgsExpressionContext *context )
{
if ( !mWebPage )
{
return;
}
const QgsExpressionContext* evalContext = context;
QScopedPointer< QgsExpressionContext > scopedContext;
if ( !evalContext )
{
scopedContext.reset( createExpressionContext() );
evalContext = scopedContext.data();
}
QString loadedHtml;
switch ( mContentMode )
{
case QgsComposerHtml::Url:
{
QString currentUrl = mUrl.toString();
//data defined url set?
QVariant exprVal;
if ( dataDefinedEvaluate( QgsComposerObject::SourceUrl, exprVal, *evalContext ) )
{
currentUrl = exprVal.toString().trimmed();
QgsDebugMsg( QString( "exprVal Source Url:%1" ).arg( currentUrl ) );
}
if ( currentUrl.isEmpty() )
{
return;
}
if ( !( useCache && currentUrl == mLastFetchedUrl ) )
{
loadedHtml = fetchHtml( QUrl( currentUrl ) );
mLastFetchedUrl = currentUrl;
}
else
{
loadedHtml = mFetchedHtml;
}
break;
}
case QgsComposerHtml::ManualHtml:
loadedHtml = mHtml;
break;
}
//evaluate expressions
if ( mEvaluateExpressions )
{
loadedHtml = QgsExpression::replaceExpressionText( loadedHtml, evalContext, nullptr, mDistanceArea );
}
mLoaded = false;
//reset page size. otherwise viewport size increases but never decreases again
mWebPage->setViewportSize( QSize( maxFrameWidth() * mHtmlUnitsToMM, 0 ) );
//set html, using the specified url as base if in Url mode
mWebPage->mainFrame()->setHtml( loadedHtml, mContentMode == QgsComposerHtml::Url ? QUrl( mActualFetchedUrl ) : QUrl() );
//set user stylesheet
QWebSettings* settings = mWebPage->settings();
if ( mEnableUserStylesheet && ! mUserStylesheet.isEmpty() )
{
QByteArray ba;
ba.append( mUserStylesheet.toUtf8() );
QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );
settings->setUserStyleSheetUrl( cssFileURL );
}
else
{
settings->setUserStyleSheetUrl( QUrl() );
}
while ( !mLoaded )
{
qApp->processEvents();
}
recalculateFrameSizes();
//trigger a repaint
emit contentsChanged();
}
示例9: loadHtml
void QgsComposerHtml::loadHtml()
{
if ( !mWebPage )
{
return;
}
QString loadedHtml;
switch ( mContentMode )
{
case QgsComposerHtml::Url:
{
QString currentUrl = mUrl.toString();
//data defined url set?
QVariant exprVal;
if ( dataDefinedEvaluate( QgsComposerObject::SourceUrl, exprVal ) )
{
currentUrl = exprVal.toString().trimmed();;
QgsDebugMsg( QString( "exprVal Source Url:%1" ).arg( currentUrl ) );
}
if ( currentUrl.isEmpty() )
{
return;
}
if ( currentUrl != mLastFetchedUrl )
{
loadedHtml = fetchHtml( QUrl( currentUrl ) );
mLastFetchedUrl = currentUrl;
}
else
{
loadedHtml = mFetchedHtml;
}
break;
}
case QgsComposerHtml::ManualHtml:
loadedHtml = mHtml;
break;
}
//evaluate expressions
if ( mEvaluateExpressions )
{
loadedHtml = QgsExpression::replaceExpressionText( loadedHtml, mExpressionFeature, mExpressionLayer );
}
mLoaded = false;
//set html, using the specified url as base if in Url mode
mWebPage->mainFrame()->setHtml( loadedHtml, mContentMode == QgsComposerHtml::Url ? QUrl( mActualFetchedUrl ) : QUrl() );
//set user stylesheet
QWebSettings* settings = mWebPage->settings();
if ( mEnableUserStylesheet && ! mUserStylesheet.isEmpty() )
{
QByteArray ba;
ba.append( mUserStylesheet.toUtf8() );
QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );
settings->setUserStyleSheetUrl( cssFileURL );
}
else
{
settings->setUserStyleSheetUrl( QUrl() );
}
while ( !mLoaded )
{
qApp->processEvents();
}
if ( frameCount() < 1 ) return;
QSize contentsSize = mWebPage->mainFrame()->contentsSize();
//find maximum frame width
double maxFrameWidth = 0;
QList<QgsComposerFrame*>::const_iterator frameIt = mFrameItems.constBegin();
for ( ; frameIt != mFrameItems.constEnd(); ++frameIt )
{
maxFrameWidth = qMax( maxFrameWidth, ( *frameIt )->boundingRect().width() );
}
//set content width to match maximum frame width
contentsSize.setWidth( maxFrameWidth * mHtmlUnitsToMM );
mWebPage->setViewportSize( contentsSize );
mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
mSize.setWidth( contentsSize.width() / mHtmlUnitsToMM );
mSize.setHeight( contentsSize.height() / mHtmlUnitsToMM );
renderCachedImage();
recalculateFrameSizes();
emit changed();
//trigger a repaint
emit contentsChanged();
}
示例10: loadSettings
bool Kludget::loadSettings(const KludgetInfo &i, bool loadPage)
{
info = i;
#if 1
qDebug("path: %s", qPrintable(info.path));
qDebug("name: %s", qPrintable(info.name));
qDebug("config: %s", qPrintable(info.configFile));
qDebug("instance config: %s", qPrintable(info.instancePreferenceFile));
qDebug("storage: %s", qPrintable(info.storagePath));
qDebug("contentSrc: %s", qPrintable(info.contentSrc));
#endif
if (!QFile::exists(info.configFile))
{
KLog::log("Kludget::load fail");
KLog::log("config file not found");
return false;
}
window->setWindowTitle(info.id + ":" + QString::number(QApplication::applicationPid()));
// access
KDocument access;
access.openDocument(info.storagePath + "/access.xml");
bool accessLocal = access.getValue("kludget/access/local", "0").toInt();
bool accessNetwork = access.getValue("kludget/access/network", "0").toInt();
bool accessPlugins = access.getValue("kludget/access/plugins", "0").toInt();
bool accessSystem = access.getValue("kludget/access/system", "0").toInt();
// engine
KDocument engine;
engine.openDocument(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/" + ENGINE_CONFIG_FILE);
// instance settings
settings->setPath(info.instancePreferenceFile);
#if defined(WIN32)
settings->loadPreferences(":resources/xml/widgetPreferences.xml");
#else
settings->loadPreferences(":resources/xml/widgetPreferences_linux.xml");
#endif
settings->loadPreferences(info.configFile);
settings->loadPreferences(info.path + "/" + PREFERENCE_FILE);
// position
int x = settings->read("kludget/x", window->x()).toInt();
int y = settings->read("kludget/y", window->y()).toInt();
window->move(x, y);
resize(settings->read("kludget/width", info.width).toInt(), settings->read("kludget/height", info.height).toInt());
window->setOpacity(settings->read("kludget/opacity", 200).toInt());
window->setIgnoreDrag(settings->read("kludget/ignoreDrag", "0").toInt());
window->setIgnoreMouse(settings->read("kludget/ignoreMouse", "0").toInt());
window->setWindowLevel(settings->read("kludget/windowLevel", "0").toInt());
window->setSnapToScreen(settings->read("kludget/snapToScreen", "0").toInt());
window->view()->setGrayed(settings->read("kludget/grayScaled", "0").toInt());
#if 0
window->view()->setTinted(settings->read("kludget/tinted", "0").toInt());
window->view()->setTintColor(QColor(settings->read("kludget/tintColor", "#c0c0c0").toString()));
window->view()->setTintMode(settings->read("kludget/tintMode", "14").toInt());
#endif
// zoom
window->setZoomFactor(settings->read("kludget/zoom", 1).toDouble());
window->view()->page()->setViewportSize(window->view()->page()->viewportSize());
window->autoSize(true);
setProperty("identifier", info.id);
setProperty("instance", info.instance);
setupContextMenu();
QWebSettings *webSettings = window->view()->page()->settings();
#if 0
webSettings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
webSettings->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
webSettings->setOfflineStoragePath(info.storagePath);
webSettings->setOfflineStorageDefaultQuota(5000000);
#endif
webSettings->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
webSettings->setAttribute(QWebSettings::PluginsEnabled, accessPlugins);
webSettings->setWebGraphic(QWebSettings::MissingImageGraphic, QPixmap());
webSettings->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, true);
webSettings->setAttribute(QWebSettings::LocalContentCanAccessFileUrls, true);
webSettings->setUserStyleSheetUrl(QUrl::fromLocalFile(":resources/style/widget.css"));
// network settings
KNetwork *net = KNetwork::instance();
net->loadSettings();
net->setAccess(accessNetwork, accessLocal, QUrl::fromLocalFile(QFileInfo(info.contentSrc).absolutePath()));
// system settings
system->setEnableCommands(accessSystem);
//.........这里部分代码省略.........