0

我想为所有按钮图像使用单个图像,并且在显示图标时,我只想显示该图像的所需范围,这可能吗?

谢谢 !

4

1 回答 1

1

您可以通过将“精灵表”读取为 QImage 并将其绘制到另一个 QImage 中来创建图标:

QIcon GetIcon(left, top, width, height) // or calculate these from an icon index or such
{
    QImage sprite, result;
    sprite = QImage(pathToSprite);
    result = QImage(resultingIconSize, theQImageFormat);
    QPainter painter(&result);
    painter.drawImage(0, 0, sprite, left, top, width, height);
    painter.end();

    return QIcon(QPixmap::fromImage(result));
}

通过设置合成模式,您甚至可以用透明度覆盖多个图像。

于 2012-02-21T12:24:45.117 回答