MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / rasterizeSvgIcon

Function rasterizeSvgIcon

pj_widgets/src/DateRangePicker.cpp:129–143  ·  view source on GitHub ↗

Rasterize already-prepared SVG bytes into a px-logical QIcon at size*DPR so it stays crisp on HiDPI. Callers own the theming/recoloring of `svg_data`; this is the shared QSvgRenderer + DPR-scaling tail behind both icon paths below (and mirrors widget_binding.cpp's render path).

Source from the content-addressed store, hash-verified

127// the shared QSvgRenderer + DPR-scaling tail behind both icon paths below (and
128// mirrors widget_binding.cpp's render path).
129QIcon rasterizeSvgIcon(const QByteArray& svg_data, int px) {
130 QSvgRenderer renderer(svg_data);
131 if (!renderer.isValid()) {
132 return QIcon();
133 }
134 const qreal dpr = qApp ? qApp->devicePixelRatio() : 1.0;
135 QImage image(QSize(px, px) * dpr, QImage::Format_ARGB32);
136 image.fill(Qt::transparent);
137 QPainter painter(&image);
138 renderer.render(&painter);
139 painter.end();
140 QPixmap pix = QPixmap::fromImage(image);
141 pix.setDevicePixelRatio(dpr);
142 return QIcon(pix);
143}
144
145// Render a qrc SVG into a theme-inked QIcon.
146QIcon renderThemedIcon(const QString& resource_path, int px = 16) {

Callers 2

renderThemedIconFunction · 0.85
renderChevronIconFunction · 0.85

Calls 5

devicePixelRatioMethod · 0.80
QSizeClass · 0.50
isValidMethod · 0.45
renderMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected