Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Change colour of QPixmap?
Qt 6.11 is out! See what's new in the release blog

Change colour of QPixmap?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CAD_codingC Offline
    CAD_codingC Offline
    CAD_coding
    wrote on last edited by
    #1

    Hello,

    I have a PNG image which contains a circle filled in white colour and the background is transparent.
    I want to use this image as an icon in my application.
    I want to allow the user to be able to change the colour of the circle (currently white) to his own.
    I have added a QLabel and set its pixmap property to the PNG file in my resources.
    I have the required colour as a QColor.

    Now, how do I modify the QPixmap so that only the white colour is changed and the background colour remains transparent?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Since it doesn't seem to be a very complicated drawing, why not generate the pixmap directly in code ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • CAD_codingC Offline
        CAD_codingC Offline
        CAD_coding
        wrote on last edited by
        #3

        Hi SGaist,

        I mentioned the circle just for simplifying the question.
        My actual image is much more complicated than that.
        Also, since the colour is decided by the user at run time, I cannot prepare the images already...

        1 Reply Last reply
        0
        • E Offline
          E Offline
          euchkatzl
          wrote on last edited by
          #4

          You can search for the white pixel in the image and set the color you want.

          http://doc-snapshot.qt-project.org/qt5-5.4/qimage.html#setPixel-2

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved