1.引入包: import QtGraphicalEffects 1.12 1. 2. 修改SVG颜色 Image{ id: image width: 48 height: 48 anchors.horizontalCenter: parent.horizontalCenter source: "svg图片路径" ColorOverlay{ anchors.fill: image source: image color: "red" //修改后的svg图片颜色 } 1. 2. 3. 4. 5. 6. 7. 8. ...
QPixmap img(svg_path); QPainter qp(&img); qp.setCompositionMode(QPainter::CompositionMode_SourceIn); qp.fillRect( img.rect(), QColor(color) ); qp.end(); return QIcon(img); } 1. 2. 3. 4. 5. 6. 7. 8. 9.