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


C++ QPixmap::alphaChannel方法代码示例

本文整理汇总了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;
}
开发者ID:9smart,项目名称:QQC_1_1_for_Symbian1,代码行数:59,代码来源:siconpool.cpp


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