本文整理汇总了C++中QTextBrowser::source方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBrowser::source方法的具体用法?C++ QTextBrowser::source怎么用?C++ QTextBrowser::source使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextBrowser
的用法示例。
在下文中一共展示了QTextBrowser::source方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getImage
static QImage getImage(QTextDocument *doc, const QTextImageFormat &format)
{
QImage image;
QString name = format.name();
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl::fromEncoded(name.toUtf8());
const QVariant data = doc->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Image) {
image = qvariant_cast<QImage>(data);
} else if (data.type() == QVariant::ByteArray) {
image.loadFromData(data.toByteArray());
}
if (image.isNull()) {
QString context;
#ifndef QT_NO_TEXTBROWSER
QTextBrowser *browser = qobject_cast<QTextBrowser *>(doc->parent());
if (browser)
context = browser->source().toString();
#endif
if (QTextImageHandler::externalLoader)
image = QTextImageHandler::externalLoader(name, context);
if (image.isNull()) { // try direct loading
name = format.name(); // remove qrc:/ prefix again
if (name.isEmpty() || !image.load(name))
return QImage(QLatin1String(":/trolltech/styles/commonstyle/images/file-16.png"));
}
doc->addResource(QTextDocument::ImageResource, url, image);
}
return image;
}
示例2: getPixmap
static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, const qreal devicePixelRatio = 1.0)
{
QPixmap pm;
QString name = format.name();
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources and convert them to url
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl(name);
name = resolveFileName(name, &url, devicePixelRatio);
const QVariant data = doc->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Pixmap || data.type() == QVariant::Image) {
pm = qvariant_cast<QPixmap>(data);
} else if (data.type() == QVariant::ByteArray) {
pm.loadFromData(data.toByteArray());
}
if (pm.isNull()) {
#if 0
QString context;
// ### Qt5
QTextBrowser *browser = qobject_cast<QTextBrowser *>(doc->parent());
if (browser)
context = browser->source().toString();
#endif
// try direct loading
QImage img;
if (name.isEmpty() || !img.load(name))
return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
pm = QPixmap::fromImage(img);
doc->addResource(QTextDocument::ImageResource, url, pm);
}
if (name.contains(QStringLiteral("@2x")))
pm.setDevicePixelRatio(2.0);
return pm;
}