Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Changing image colour programatically in QML
Forum Updated to NodeBB v4.3 + New Features

Changing image colour programatically in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlqtquickqt5.9
5 Posts 3 Posters 5.5k 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.
  • B Offline
    B Offline
    BikashRDas
    wrote on 16 Dec 2020, 15:56 last edited by
    #1

    I am using:
    Qt 5.9.4

    I am working on some image icons. Depending on the state, the image colour needs to be changed accordingly.
    For example:
    Not selected state:
    square_black.png
    Selected state:
    square_green.png
    Note: Above images are for demo purpose only. These are not the images I am using in my application.

    I have the image icon files for "not selected" state for my application.

    My question:
    Is it possible to dynamically change the image colour to another (keeping the alpha values unchanged)? In the above example suppose if I have the image for not selected state, can I dynamically change the colour in the image using QML coding to achieve selected state image?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mnesarco
      wrote on 16 Dec 2020, 16:07 last edited by
      #2

      Hi @BikashRDas , why not using icon fonts? I am using icon fonts now exclusivelly for all icons in QML, they are powerful, scalable, easy, and you can do anything that you can do with text to your icons.

      I create all my icons in SVG using Inkscape, and import other icons from Free Internet libraries like bootstrap-icons. Then I create a font, add it to my App and thats it, All icons are available to be used anywhere where text can be used.

      Cheers,
      Frank.

      1 Reply Last reply
      2
      • F Offline
        F Offline
        fcarney
        wrote on 16 Dec 2020, 16:30 last edited by
        #3

        I remember doing this, but cannot remember what mechanism I used. It looks like however, there are a few ways:
        https://stackoverflow.com/questions/16839198/qml-change-image-color

        I am not sure if all of these are avialable in 5.9 though.

        C++ is a perfectly valid school of magic.

        B 1 Reply Last reply 17 Dec 2020, 04:45
        1
        • F Offline
          F Offline
          fcarney
          wrote on 16 Dec 2020, 17:02 last edited by
          #4

          @fcarney said in Changing image colour programatically in QML:

          I remember doing this

          I found how we colored images on a button:

                  Button {
                      icon.source: "https://www.qt.io/hubfs/2016_Qt_Logo/qt_logo_green_rgb_16x16.png"
                      icon.color: "transparent"
                  }
                  Button {
                      icon.source: "https://www.qt.io/hubfs/2016_Qt_Logo/qt_logo_green_rgb_16x16.png"
                      icon.color: "#77ff0000"
                  }
          

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          0
          • F fcarney
            16 Dec 2020, 16:30

            I remember doing this, but cannot remember what mechanism I used. It looks like however, there are a few ways:
            https://stackoverflow.com/questions/16839198/qml-change-image-color

            I am not sure if all of these are avialable in 5.9 though.

            B Offline
            B Offline
            BikashRDas
            wrote on 17 Dec 2020, 04:45 last edited by
            #5

            Thanks every one for your reply. @fcarney The ColorOverlay is working fine for me. Thanks for the same.

            1 Reply Last reply
            0

            1/5

            16 Dec 2020, 15:56

            • Login

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