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. How to make ToolButton icon grayscale?
Qt 6.11 is out! See what's new in the release blog

How to make ToolButton icon grayscale?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 1.2k Views
  • 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
    Dmitriano
    wrote on last edited by
    #1

    I have a QML app with a ToolBar with ToolButtons with images, for example, a ToolButton that loads something is defined in QML in this way:

    ToolButton {
        contentItem: Image { source: "Icons/load.png" }
        enabled: scene.loadEnabled
        onClicked: loadDialog.open()
    }
    

    and I am looking for a sample code that automatically makes the icon grayscale when the ToolButton is disabled.

    Should I manually implement the algorithm that makes the image graysacle and bind Image.source to a property returning the resulting image or there is a better way?

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      You can do it with Desaturate :

      import QtGraphicalEffects 1.0
      ...
      
          contentItem: Image {
              source: "Icons/load.png"
              layer.enabled: true
              layer.effect: Desaturate {
                  desaturation: parent.enabled ? 0 : 1
                  Behavior on desaturation { NumberAnimation { easing.type: Easing.InOutQuad } }
              }
          }
      
      1 Reply Last reply
      1

      • Login

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