本文整理汇总了C++中QPixmap::alphaChannel方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::alphaChannel方法的具体用法?C++ QPixmap::alphaChannel怎么用?C++ QPixmap::alphaChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::alphaChannel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadIcon
QPixmap SIconPool::loadIcon(
const QString &fileName,
const QSize &size,
Qt::AspectRatioMode mode,
const QColor &color)
{
QPixmap pm;
// SVG? Use QSvgRenderer
if (fileName.endsWith(".svg")) {
QSvgRenderer *renderer = getSvgRenderer(fileName);
if (renderer->isValid()) {
QSize renderSize = renderer->defaultSize();
// If given size is valid, scale default size to it using the given aspect ratio mode
if (size.isValid()) {
renderSize.scale(size, mode);
// If only one dimension is valid, scale other dimension keeping the aspect ratio
} else if (size.height() > 0) {
Qt::AspectRatioMode scaleMode = size.height() > renderSize.height()
? Qt::KeepAspectRatioByExpanding
: Qt::KeepAspectRatio;
renderSize.scale(renderSize.width(), size.height(), scaleMode);
} else if (size.width() > 0) {
Qt::AspectRatioMode scaleMode = size.width() > renderSize.width()
? Qt::KeepAspectRatioByExpanding
: Qt::KeepAspectRatio;
renderSize.scale(size.width(), renderSize.height(), scaleMode);
}
// Otherwise (-1,-1) was given as size, leave renderSize as icon's default size
pm = QPixmap(renderSize);
pm.fill(QColor(0, 0, 0, 0));
QPainter painter(&pm);
renderer->render(&painter, QRectF(QPointF(), renderSize));
}
} else {
// Otherwise load with QPixmap
pm.load(fileName);
if (!pm.isNull()) {
pm = pm.scaled(size, mode, Qt::SmoothTransformation);
}
}
if (!pm.isNull() && color.isValid()) {
// Colorize the icon
QPixmap mask = pm.alphaChannel();
pm.fill(color);
pm.setAlphaChannel(mask);
}
#ifdef Q_DEBUG_ICON
if (pm.isNull()) {
qDebug() << "Fail to load icon: " << filename;
}
#endif
return pm;
}