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. Icon foreground color modification
Forum Updated to NodeBB v4.3 + New Features

Icon foreground color modification

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.4k 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.
  • D Offline
    D Offline
    dbarrett
    wrote on last edited by
    #1

    I have an icon in .png format that is essentially a black symbol with a clear background. I'd like to apply this icon to a QPushButton, but with the color of the black foreground image to be set dynamically (not always black). Is there a good way to do this? I could produce multiple .png files with different colors, but I'd like the dynamic color range of the icon to be more "continuous" if possible.

    Thanks in advance!
    -Dan

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      You could try to turn the black pixels into transparent ones and set a background color on the button. This has the drawback that the complete button has that background color. There's no easy built-in way in Qt to change all pixels of a certain color to another color.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbarrett
        wrote on last edited by
        #3

        That would unfortunately result in the entire image being transparent.

        If not the ability to change the color of all pixels of a certain color, how about the ability to set the color of all opaque pixels? This would achieve the same result in this case since all opaque pixels are of the same color.

        Thanks,
        Dan

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Well, you could load the image into a QImage, and loop over the pixels. You can change them one-by-one that way. If the shape is not very complicated, it would perhaps be better to just draw it yourself in the right color in Qt? Or, perhaps you can use Qt SVG capabilities and use that to render the shape in the right color?

          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