Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML change image color

Tags:

I searched for how to colorize an image (with the format svg or png ...).

I tried covering my image with a rectangle that fills the image, but as my image is not a rectangle it colorizes the whole rectangle and not just the image.

Is it possible to change image color with qml? Alternatively, is it possible to change the color on qt (with C++) with QPixmap then integrate the QPixmap on QML Item?

Thank you for your help. (If there is no solution, I will have to load a different image to the same basic image with different color.)

like image 663
helene Avatar asked May 30 '13 14:05

helene


1 Answers

In Qt 5 (from 5.2) you may use ColorOverlay as follows:

import QtQuick 2.0 import QtGraphicalEffects 1.0  Item {     width: 300     height: 300      Image {         id: bug         source: "images/butterfly.png"         sourceSize: Qt.size(parent.width, parent.height)         smooth: true         visible: false     }      ColorOverlay {         anchors.fill: bug         source: bug         color: "#ff0000"  // make image like it lays under red glass      }  } 

In Qt 6 module QtGraphicalEffects (which includes ColorOverlay) was removed because of licensing issues.

In Qt 6.1 GraphicalEffects is now available again, as @SCP3008 commented below

like image 126
Nikolai Saiko Avatar answered Dec 10 '22 12:12

Nikolai Saiko