2012-02-21 9 views
0

すべてのボタンイメージに1つのイメージを使用したいと思っていました。アイコンを表示するときに、そのイメージの希望する範囲のみを表示したかったのですか?QIcon表示部分の画像は可能ですか?

ありがとうございます!

答えて

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)); 
} 

あなたも透明で複数の画像をオーバーレイすることができcomposition modeを設定すること。

関連する問題