svg_util.h
Go to the documentation of this file.
1 #ifndef PJ_SVG_UTIL_H
2 #define PJ_SVG_UTIL_H
3 
4 #ifdef QT_NO_SVGRENDERER
5  #error "QT_NO_SVGRENDERER defined"
6 #endif
7 
8 #include <QtSvg>
9 #include <QFile>
10 #include <QIcon>
11 #include <QTextStream>
12 #include <QByteArray>
13 #include <QPainter>
14 #include <QPixmap>
15 #include <QDebug>
16 
17 inline QIcon LoadSvgIcon(QString filename, QString style_name = "light")
18 {
19  QFile file(filename);
20  file.open(QFile::ReadOnly | QFile::Text);
21  auto svg_data = file.readAll();
22  file.close();
23 
24  if( style_name.contains("light") )
25  {
26  svg_data.replace("#000000", "#111111");
27  svg_data.replace("#ffffff", "#dddddd");
28  }
29  else{
30  svg_data.replace("#000000", "#dddddd");
31  svg_data.replace("#ffffff", "#111111");
32  }
33 
34  QByteArray content(svg_data);
35 
36  QSvgRenderer rr( content );
37  QImage image(64, 64, QImage::Format_ARGB32);
38  QPainter painter(&image);
39  image.fill(Qt::transparent);
40  rr.render(&painter);
41 
42  return QIcon(QPixmap::fromImage(image));
43 }
44 
45 
46 #endif // PJ_SVG_UTIL_H
QIcon LoadSvgIcon(QString filename, QString style_name="light")
Definition: svg_util.h:17


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:47