Last active
October 23, 2022 05:27
-
-
Save SC-One/c56caade8fa44562b75511f41192641e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//IconLabel is subclass of QLabel | |
//Note: if you wanna keep Quality , you should create pixmap for all sizes (so override resizeEvent !) | |
// this method is working normally | |
QPixmap IconLabel::FromSvgToPixmap(const QString &SvgFile, | |
const QSize &ImageSize) { | |
QSvgRenderer SvgRenderer(SvgFile); | |
QPixmap Image(ImageSize); | |
QPainter Painter; | |
Image.fill(Qt::transparent); | |
Painter.begin(&Image); | |
SvgRenderer.render(&Painter); | |
Painter.end(); | |
return Image; | |
} | |
// this method is working normally too but when we have a monitor that has more pixle ratio we should | |
// improve shrunkened image that keep real size | |
QPixmap IconLabel::FromSvgToPixmap(const QSize &ImageSize, | |
const QString &SvgFile) { | |
const qreal PixelRatio = qApp->primaryScreen()->devicePixelRatio(); | |
QSvgRenderer SvgRenderer(SvgFile); | |
QPixmap Image(ImageSize * PixelRatio); | |
QPainter Painter; | |
Image.fill(Qt::transparent); | |
Painter.begin(&Image); | |
SvgRenderer.render(&Painter); | |
Painter.end(); | |
Image.setDevicePixelRatio(PixelRatio); | |
return Image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment