0
我想爲我的所有按鈕圖像使用單個圖像,並且在顯示圖標時,我只想顯示該圖像的所需範圍,可以嗎?QIcon顯示圖像的一部分,可能嗎?
謝謝!通過設置composition mode你甚至可以覆蓋多個圖像的透明度
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));
}
: