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).
| 127 | // the shared QSvgRenderer + DPR-scaling tail behind both icon paths below (and |
| 128 | // mirrors widget_binding.cpp's render path). |
| 129 | QIcon 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. |
| 146 | QIcon renderThemedIcon(const QString& resource_path, int px = 16) { |
no test coverage detected