Qt-interest Archive, August 2007
2D gradients
Message 1 in thread
Hi,
I have searched quite a bit on this, but I can't seem to find it. I hope
somebody here might have a hint how to approach this.
I am trying to fill a polygon. It's quite a simple one, almost a square.
However, I want to be able to set a color for each of the four corners, and
fill the polygon using a linear gradient that matches these colors so the
color will change fluidly from one corner to the next. Can anyone tell me
how to approach this? In the documentation of Qt, I only find methods to
set colors along a line (1D). Any Qt 4.x version would do, by the way.
Regards,
André
--
[ signature omitted ]
Message 2 in thread
I don't think that there already exists something like that.
Qt::TexturePattern / QBrush::setTextureImage could be a workaround. (create the texture on the fly)
Cheers,
Peter
> -----Original Message-----
> From: André Somers [mailto:andre@xxxxxxxxx]
> Sent: Friday, August 10, 2007 7:02 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: 2D gradients
>
> Hi,
>
> I have searched quite a bit on this, but I can't seem to find it. I hope
> somebody here might have a hint how to approach this.
>
> I am trying to fill a polygon. It's quite a simple one, almost a square.
> However, I want to be able to set a color for each of the four corners,
> and
> fill the polygon using a linear gradient that matches these colors so the
> color will change fluidly from one corner to the next. Can anyone tell me
> how to approach this? In the documentation of Qt, I only find methods to
> set colors along a line (1D). Any Qt 4.x version would do, by the way.
>
> Regards,
>
> André
--
[ signature omitted ]
Message 3 in thread
Peter Prade wrote:
> I don't think that there already exists something like that.
>
> Qt::TexturePattern / QBrush::setTextureImage could be a workaround.
> (create the texture on the fly)
Hi, thanks for your reply. Your solution doesn't bring the answer much
closer, as I'd still need a way to create the textures. As they are not
fixed in advance, I wouldn't know how to create them, let alone how to do
that efficiently...
André
--
[ signature omitted ]
Message 4 in thread
You will not be able to do this with the canned gradients. You are
creating a color wheel. QTSolutions has an implementation of this in
QtColorTriangle.
What you need to do is this. I'm going to give you an algorithm that
is unoptimized. You calculate a line from corner to non adjacent
corner. You step the rgb colors from the first point, color
coordinate to the second, color coordinate. You can use the line
distance formula to calculate the step size. For example, if you are
going from R:10 G:20 B:50 to R:110 G:40 B:100, and the distance is 50
pixels, your step size per pixel movement is R:2 (110-10)/50 , G:.4
(40-20)/50 and B:1 (100-50) / 50. That gives you the pixel colors of
the diagonals. You then step the diagonal and apply a color gradient
from D1 to D2. D1 and D2 are points on the diagonal line calculated
between the non adjacent points.
Michael
On Aug 10, 2007, at 11:26 AM, André Somers wrote:
> Peter Prade wrote:
>
>> I don't think that there already exists something like that.
>>
>> Qt::TexturePattern / QBrush::setTextureImage could be a workaround.
>> (create the texture on the fly)
>
> Hi, thanks for your reply. Your solution doesn't bring the answer much
> closer, as I'd still need a way to create the textures. As they are
> not
> fixed in advance, I wouldn't know how to create them, let alone how
> to do
> that efficiently...
>
> André
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
Message 5 in thread
There are many ways to fill a texture given the corner colors,
one possible way would be
http://en.wikipedia.org/wiki/Bicubic_interpolation
Cheers,
Peter
> -----Original Message-----
> From: André Somers [mailto:andre@xxxxxxxxx]
> Sent: Friday, August 10, 2007 8:26 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: RE: 2D gradients
>
>
> Peter Prade wrote:
>
> > I don't think that there already exists something like that.
> >
> > Qt::TexturePattern / QBrush::setTextureImage could be a workaround.
> > (create the texture on the fly)
>
> Hi, thanks for your reply. Your solution doesn't bring the answer much
> closer, as I'd still need a way to create the textures. As
> they are not
> fixed in advance, I wouldn't know how to create them, let
> alone how to do
> that efficiently...
>
> André
>
> --
> To unsubscribe - send a mail to
> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the
> subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]