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. How to set a bidirectional color gradient
Forum Update on Monday, May 27th 2025

How to set a bidirectional color gradient

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 747 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.
  • Ioseph12I Offline
    Ioseph12I Offline
    Ioseph12
    wrote on last edited by
    #1

    Hi everyone,

    I'm trying to draw a rectangle with a color gradient. In addition, I need that some sections of the rectangle have different heights. To achieve this what I want to do is something like this:

    QLinearGradient grad(0,0,1,0);
    grad.setColorAt(0, Color1);
    grad.SetColotAt(0.3, Color2);
    grad.SetColotAt(0.31, Color3);
    grad.setColorAt(1, Color4);

    and, for example, if i want that the rectangle has 0.5 of height between 0 and 0.3 what I would try to do is define Color1 and Color2 as vertical color gradients where only changes alpha.

    Could it be possible to do something like this ??

    Thank's for your time!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Yes I think its possible.
      You could use the built in editor to experiment.

      alt text

      1 Reply Last reply
      3
      • Ioseph12I Offline
        Ioseph12I Offline
        Ioseph12
        wrote on last edited by
        #3

        It's a good approach, but as the vertical gradient was intended to modify the width of the rectangle it hasn't fitted.

        So, what i finally made is create a function which creates little pixmaps from desired height and color gradients and, just after this I paint them into a bigger pixmap

        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