Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//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