Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Linear Gradient on Alpha (Not Color)
Qt 6.12 LTS is out! See what's new in the release blog

Linear Gradient on Alpha (Not Color)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 4.7k 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.
  • H Offline
    H Offline
    Hoyt
    wrote on last edited by
    #1

    QML includes a LinearGradient method that blends two colors. Is there any QML method that allows a linear gradient to be applied to an image's alpha?

    I am trying to fade an image in via a gradient.

    Hoyt

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Have a look at Graphical Effects.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hoyt
        wrote on last edited by
        #3

        Weiland,

        Thank you for your response. I have reviewed Graphical Effects. I see the LinearGradient method, which relates to color gradients, but I do not see any method related to programmatically generating a gradient for alpha. I also see the OpacityMask, but do not know of a good way to use that method to programmatically generate a dynamic alpha gradient.

        Hoyt

        J.HilkJ 1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #4

          Hmm.. I had hoped that Graphical Effects would offer something for you OOTB. If everything else fails you can implement any effect you like using ShaderEffect QML Type. I didn't look it up but I guess that's just how the stuff in Graphical effects is implemented. It has a QML API so that might be handy. If going that road turns out to be too hard you could also craft a solution in C++ that manipulates a QImage, maybe based on QQuickPaintedItem Class. That will probably be suboptimal performance-wise but might be easier and better than nothing. @J.Hilk is the man!

          1 Reply Last reply
          0
          • H Hoyt

            Weiland,

            Thank you for your response. I have reviewed Graphical Effects. I see the LinearGradient method, which relates to color gradients, but I do not see any method related to programmatically generating a gradient for alpha. I also see the OpacityMask, but do not know of a good way to use that method to programmatically generate a dynamic alpha gradient.

            Hoyt

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Hoyt hi, just tested it, LineGradient should work with alpha as well:
            take this example:

            import QtQuick 2.8
            import QtQuick.Window 2.2
            import QtGraphicalEffects 1.0
            
            Window {
                visible: true
            
                title: qsTr("Hello World")
            
                width: 300
                height: 300
                Rectangle{
                    anchors.fill:parent
                    color: "red"
                }
            
                LinearGradient {
                    anchors.fill: parent
                    start: Qt.point(0, 0)
                    end: Qt.point(0, 300)
                    gradient: Gradient {
                        GradientStop { position: 0.0; color: "#00FFFFFF" }
                        GradientStop { position: 1.0; color: "#FFFFFFFF" }
                    }
                }
            }
            

            The Linear Gradient describes an Alpha change from transparent to white on a red background.
            Works fine for me.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            H 1 Reply Last reply
            1
            • J.HilkJ J.Hilk

              @Hoyt hi, just tested it, LineGradient should work with alpha as well:
              take this example:

              import QtQuick 2.8
              import QtQuick.Window 2.2
              import QtGraphicalEffects 1.0
              
              Window {
                  visible: true
              
                  title: qsTr("Hello World")
              
                  width: 300
                  height: 300
                  Rectangle{
                      anchors.fill:parent
                      color: "red"
                  }
              
                  LinearGradient {
                      anchors.fill: parent
                      start: Qt.point(0, 0)
                      end: Qt.point(0, 300)
                      gradient: Gradient {
                          GradientStop { position: 0.0; color: "#00FFFFFF" }
                          GradientStop { position: 1.0; color: "#FFFFFFFF" }
                      }
                  }
              }
              

              The Linear Gradient describes an Alpha change from transparent to white on a red background.
              Works fine for me.

              H Offline
              H Offline
              Hoyt
              wrote on last edited by
              #6

              Truly impressive! Thank you very much.

              Hoyt

              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
              • Unsolved