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. Can't able to change the pixmap color with QLinearGradient

Can't able to change the pixmap color with QLinearGradient

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 639 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.
  • A Offline
    A Offline
    Aravinth Ravi
    wrote on 16 Feb 2023, 12:15 last edited by
    #1

    I'm using masking operation (Qt::MaskInColor) for the pixmap. Except the masked region from the pixmap, I'm trying to fill the remaining region of the pixmap with the QLinearGradient (color gradient).

    If I did'nt use the masking operation, the entire pixmap is filled with the color gradient (using QLinearGradient). But I want to fill the color gradient in the specific region of the pixmap. I could'nt find a way to do this.

    Provide me some solutions to sort out this issue. Thanks in advance.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Feb 2023, 20:28 last edited by
      #2

      Hi,

      You might be interested by the Painting Composition example.

      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
      • A Offline
        A Offline
        Aravinth Ravi
        wrote on 21 Feb 2023, 04:43 last edited by
        #3

        Hi,
        This is the original image. In this image the background color is purple.Original_img.png

        From the above image we have masked the purple color using Qt::MaskFromColor function. Masked_img.png

        After masking the purple color, I have tried to apply the color gradient on the icon. But I can't apply the color gradient on the icon. The color gradient is getting applied on the whole image. Atlast, I have have managed to apply a solid color to the icon.SolidColor_img.png

        Like the above image, I have tried to fill the linearcolorGradient in the icon instead of solid green color.

        Is this possible to fill the Icon with color gradient?
        Thanks in advance.

        A 1 Reply Last reply 23 Feb 2023, 07:04
        0
        • A Aravinth Ravi
          21 Feb 2023, 04:43

          Hi,
          This is the original image. In this image the background color is purple.Original_img.png

          From the above image we have masked the purple color using Qt::MaskFromColor function. Masked_img.png

          After masking the purple color, I have tried to apply the color gradient on the icon. But I can't apply the color gradient on the icon. The color gradient is getting applied on the whole image. Atlast, I have have managed to apply a solid color to the icon.SolidColor_img.png

          Like the above image, I have tried to fill the linearcolorGradient in the icon instead of solid green color.

          Is this possible to fill the Icon with color gradient?
          Thanks in advance.

          A Offline
          A Offline
          Aravinth Ravi
          wrote on 23 Feb 2023, 07:04 last edited by
          #4

          Hi @SGaist ,

          Painting composition will fill the color in the entire bounding rect of the given shapes. And also it will not fill the gradient color. Is it possible to fill the gradient color only on the Icon except the background region. Thanks in advance.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 23 Feb 2023, 22:08 last edited by
            #5

            Do you mean in a similar fashion as the Wiggly example ?

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

            A 1 Reply Last reply 24 Feb 2023, 04:55
            0
            • S SGaist
              23 Feb 2023, 22:08

              Do you mean in a similar fashion as the Wiggly example ?

              A Offline
              A Offline
              Aravinth Ravi
              wrote on 24 Feb 2023, 04:55 last edited by
              #6

              @SGaist,

              In Wiggly widget, we are using lineEdit as a input. But in my application, I'm using a png image as a pixmap and I have to provide color gradient to that pixmap like the below image.
              Sample.png

              And also in wiggly widget, there will be a change in color gradient from letter to letter. But for my application I need a color gradient change in each letter.

              J 1 Reply Last reply 24 Feb 2023, 15:27
              0
              • A Aravinth Ravi
                24 Feb 2023, 04:55

                @SGaist,

                In Wiggly widget, we are using lineEdit as a input. But in my application, I'm using a png image as a pixmap and I have to provide color gradient to that pixmap like the below image.
                Sample.png

                And also in wiggly widget, there will be a change in color gradient from letter to letter. But for my application I need a color gradient change in each letter.

                J Offline
                J Offline
                JoeCFD
                wrote on 24 Feb 2023, 15:27 last edited by
                #7

                @Aravinth-Ravi
                since you know background color, do a loop through all pixels. If the pixel color is background color, ignore the pixel. Otherwise, apply your gradient.
                https://forum.qt.io/topic/136223/change-pixel-color-of-qpixmap

                A 1 Reply Last reply 28 Feb 2023, 09:33
                0
                • J JoeCFD
                  24 Feb 2023, 15:27

                  @Aravinth-Ravi
                  since you know background color, do a loop through all pixels. If the pixel color is background color, ignore the pixel. Otherwise, apply your gradient.
                  https://forum.qt.io/topic/136223/change-pixel-color-of-qpixmap

                  A Offline
                  A Offline
                  Aravinth Ravi
                  wrote on 28 Feb 2023, 09:33 last edited by
                  #8

                  Hi @JoeCFD,

                  Thanks, your idea is working. I have iterated through all the pixels and I have ignored the background color pixels. While iterating through the image, I have incremented the RGB channel data values to apply gradient inside the icon.

                  1 Reply Last reply
                  0
                  • A Aravinth Ravi has marked this topic as solved on 28 Feb 2023, 09:33

                  7/8

                  24 Feb 2023, 15:27

                  • Login

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