fix: icons in contrast icon set not correctly drawn

This commit is contained in:
Roy Qu 2022-02-05 22:26:02 +08:00
parent 6b64927b94
commit 3831c72558
1 changed files with 18 additions and 4 deletions

View File

@ -12,10 +12,24 @@ CustomDisabledIconEngine::CustomDisabledIconEngine()
void CustomDisabledIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
{
// if (mode == QIcon::Active && state == QIcon::On)
// painter->drawPixmap(rect,mPixmap);
// else
// painter->drawPixmap(rect,mDisabledPixmap);
painter->save();
painter->setClipRect(rect);
QRect newRect = rect;
QPixmap pixmap;
if (mode == QIcon::Mode::Disabled)
pixmap = mDisabledPixmap;
else
pixmap = mPixmap;
if (pixmap.size().width() < rect.width()) {
newRect.setLeft( rect.left()+(rect.width() - pixmap.size().width())/2);
newRect.setWidth(pixmap.size().width());
}
if (pixmap.size().height() < rect.height()) {
newRect.setTop( rect.top()+(rect.height() - pixmap.size().height())/2);
newRect.setHeight(pixmap.size().height());
}
painter->drawPixmap(newRect,pixmap);
painter->restore();
}
QIconEngine *CustomDisabledIconEngine::clone() const